Skip to content

Commit 68d6cc4

Browse files
committed
feat. auto update tbb meta
1 parent df9df1f commit 68d6cc4

File tree

6 files changed

+68
-2
lines changed

6 files changed

+68
-2
lines changed

.env

+1
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,6 @@ COST_PROCESS_ABNORMAL_CRON_SCHEDULE=0 0 1,7 * * ?
3434
COST_SELECTOR_URL=http://costselector:8083
3535
ALARM_URL=http://alarmservice:9000
3636
# AssetCollector
37+
COST_BE_URL=http://be:9090
3738
ASSET_MONITORING_SERVER=http://asset.mornitor.server:8080
3839
ASSET_COLLECT_BATCH_CRON_SCHEDULE=0 0 0 * * ?

assetCollector/src/main/java/com/mcmp/assetcollector/batch/AssetCollect.java

+8
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ public class AssetCollect {
5252
@Autowired
5353
private AssetCollectService assetCollectService;
5454

55+
@Autowired
56+
private UpdateMetaBeforeAssetJob updateMetaBeforeAssetJob;
57+
5558
@Bean
5659
public SkipLogListener skipLogListener(){
5760
return new SkipLogListener();
@@ -61,6 +64,7 @@ public SkipLogListener skipLogListener(){
6164
public Job assetCollectJob(JobRepository jobRepository, Step assetCollectStep) {
6265
return new JobBuilder("assetCollectJob", jobRepository)
6366
.start(assetCollectStep)
67+
.listener(updateMetaBeforeAssetJob)
6468
.build();
6569
}
6670

@@ -127,6 +131,10 @@ public ItemProcessor<RunningInstanceModel, List<RSRCAssetComputeMetricModel>> pr
127131
OffsetDateTime offsetDateTime = OffsetDateTime.parse(timestampString, DateTimeFormatter.ISO_DATE_TIME);
128132
Timestamp timestamp = Timestamp.valueOf(offsetDateTime.atZoneSameInstant(ZoneOffset.UTC).toLocalDateTime());
129133

134+
if(value.get(valueIndex) == null){
135+
log.warn("item : {}'s value is null when {}", item, timestamp);
136+
continue;
137+
}
130138
Double asset_idle_Value = (Double) value.get(valueIndex);
131139
Double roundedValue = Math.round(asset_idle_Value * 100.0) / 100.0;
132140
Double usageValue = 100 - roundedValue;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.mcmp.assetcollector.batch;
2+
3+
import com.mcmp.assetcollector.service.MetaService;
4+
import lombok.extern.slf4j.Slf4j;
5+
import org.apache.catalina.core.ApplicationContext;
6+
import org.springframework.batch.core.JobExecution;
7+
import org.springframework.batch.core.JobExecutionListener;
8+
import org.springframework.beans.factory.annotation.Autowired;
9+
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
10+
import org.springframework.stereotype.Component;
11+
12+
@Component
13+
@Slf4j
14+
public class UpdateMetaBeforeAssetJob implements JobExecutionListener {
15+
16+
@Autowired
17+
private MetaService metaService;
18+
19+
@Override
20+
public void beforeJob(JobExecution jobExecution){
21+
try{
22+
metaService.updateSvcGrpMeta();
23+
} catch (Exception e){
24+
log.error("[AssetCollect] Update ServiceGroup Meta Error : {}", e.getMessage());
25+
e.printStackTrace();
26+
}
27+
28+
}
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.mcmp.assetcollector.service;
2+
3+
import lombok.extern.slf4j.Slf4j;
4+
import org.springframework.beans.factory.annotation.Value;
5+
import org.springframework.http.HttpEntity;
6+
import org.springframework.http.HttpHeaders;
7+
import org.springframework.http.HttpMethod;
8+
import org.springframework.stereotype.Service;
9+
import org.springframework.web.client.RestTemplate;
10+
11+
@Service
12+
@Slf4j
13+
public class MetaService {
14+
@Value("${costopti.be.url}")
15+
private String costoptiBEUrl;
16+
17+
public void updateSvcGrpMeta() {
18+
RestTemplate restTemplate = new RestTemplate();
19+
String apiUrl = String.format("%s/api/costopti/be/updateRscMeta", costoptiBEUrl);
20+
21+
HttpHeaders httpHeaders = new HttpHeaders();
22+
HttpEntity<?> httpEntity = new HttpEntity<>(httpHeaders);
23+
24+
restTemplate.exchange(apiUrl, HttpMethod.GET, httpEntity, Void.class);
25+
}
26+
}

assetCollector/src/main/resources/application.properties

+3-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ spring.datasource.hikari.batch.remove-abandoned-timeout=30
1717
logging.level.org.springframework.batch=DEBUG
1818
logging.level.org.mybatis=DEBUG
1919

20-
asset.collect.url=http://monitoring.server:8080
20+
costopti.be.url=http://localhost:9090
21+
asset.collect.url=http://observability.server:8080
2122

22-
assetCollectBatchCronSchedule=0 0 0 * * ?
23+
assetCollectBatchCronSchedule=0 10 * * * ?

docker-compose.yml

+1
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ services:
105105
spring.datasource.hikari.batch.jdbc-url: ${COST_DB_URL}
106106
spring.datasource.hikari.batch.username: ${COST_DB_USERNM}
107107
spring.datasource.hikari.batch.password: ${COST_DB_PW}
108+
costopti.be.url: ${COST_BE_URL}
108109
asset.collect.url: ${ASSET_MONITORING_SERVER}
109110
assetCollectBatchCronSchedule: ${ASSET_COLLECT_BATCH_CRON_SCHEDULE}
110111
networks:

0 commit comments

Comments
 (0)