Skip to content

Commit

Permalink
Merge pull request #21 from BSjaeyoung-kim/main
Browse files Browse the repository at this point in the history
feature update
  • Loading branch information
BSjaeyoung-kim authored Nov 19, 2024
2 parents 5917635 + e8beb22 commit cd34d12
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 3,986 deletions.
3 changes: 2 additions & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,6 @@ COST_PROCESS_ABNORMAL_CRON_SCHEDULE=0 0 1,7 * * ?
COST_SELECTOR_URL=http://costselector:8083
ALARM_URL=http://alarmservice:9000
# AssetCollector
COST_BE_URL=http://be:9090
ASSET_MONITORING_SERVER=http://asset.mornitor.server:8080
ASSET_COLLECT_BATCH_CRON_SCHEDULE=0 0 0 * * ?
ASSET_COLLECT_BATCH_CRON_SCHEDULE=0 10 * * * ?
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ This repository provides a Multi-Cloud Cost Management and Optimizing Framework.
## 3. DDL/DML execution
### sql file path : /mc-cost-optimizer/mysql
### running script
mysql -u mcmpcostopti -p < init_cost_db.sql
mysql -u mcmpcostopti -p < init_cost_db_ddl.sql
mysql -u mcmpcostopti -p < init_mail_db.sql
mysql -u mcmpcostopti -p < init_slack_db.sql
```
Expand Down Expand Up @@ -72,7 +72,7 @@ This repository provides a Multi-Cloud Cost Management and Optimizing Framework.
- mysql version : 8
- run script
```
- /mc-cost-optimizer/mysql/init_cost_db.sql
- /mc-cost-optimizer/mysql/init_cost_db_ddl.sql
- /mc-cost-optimizer/mysql/init_mail_db.sql
- /mc-cost-optimizer/mysql/init_slack_db.sql
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ public class AssetCollect {
@Autowired
private AssetCollectService assetCollectService;

@Autowired
private UpdateMetaBeforeAssetJob updateMetaBeforeAssetJob;

@Bean
public SkipLogListener skipLogListener(){
return new SkipLogListener();
Expand All @@ -61,6 +64,7 @@ public SkipLogListener skipLogListener(){
public Job assetCollectJob(JobRepository jobRepository, Step assetCollectStep) {
return new JobBuilder("assetCollectJob", jobRepository)
.start(assetCollectStep)
.listener(updateMetaBeforeAssetJob)
.build();
}

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

if(value.get(valueIndex) == null){
log.warn("item : {}'s value is null when {}", item, timestamp);
continue;
}
Double asset_idle_Value = (Double) value.get(valueIndex);
Double roundedValue = Math.round(asset_idle_Value * 100.0) / 100.0;
Double usageValue = 100 - roundedValue;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.mcmp.assetcollector.batch;

import com.mcmp.assetcollector.service.MetaService;
import lombok.extern.slf4j.Slf4j;
import org.apache.catalina.core.ApplicationContext;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobExecutionListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class UpdateMetaBeforeAssetJob implements JobExecutionListener {

@Autowired
private MetaService metaService;

@Override
public void beforeJob(JobExecution jobExecution){
try{
metaService.updateSvcGrpMeta();
} catch (Exception e){
log.error("[AssetCollect] Update ServiceGroup Meta Error : {}", e.getMessage());
e.printStackTrace();
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.mcmp.assetcollector.service;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

@Service
@Slf4j
public class MetaService {
@Value("${costopti.be.url}")
private String costoptiBEUrl;

public void updateSvcGrpMeta() {
RestTemplate restTemplate = new RestTemplate();
String apiUrl = String.format("%s/api/costopti/be/updateRscMeta", costoptiBEUrl);

HttpHeaders httpHeaders = new HttpHeaders();
HttpEntity<?> httpEntity = new HttpEntity<>(httpHeaders);

restTemplate.exchange(apiUrl, HttpMethod.GET, httpEntity, Void.class);
}
}
5 changes: 3 additions & 2 deletions assetCollector/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ spring.datasource.hikari.batch.remove-abandoned-timeout=30
logging.level.org.springframework.batch=DEBUG
logging.level.org.mybatis=DEBUG

asset.collect.url=http://monitoring.server:8080
costopti.be.url=http://localhost:9090
asset.collect.url=http://observability.server:8080

assetCollectBatchCronSchedule=0 0 0 * * ?
assetCollectBatchCronSchedule=0 10 * * * ?
24 changes: 9 additions & 15 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ version: '3'
services:
be:
restart: always
build:
context: ./BackEnd
image: cloudbaristaorg/mc-costopti-api:edge
networks:
- mcmp_cost_network
ports:
Expand All @@ -22,16 +21,14 @@ services:
costopti.costselector.url: ${COST_SELECTOR_URL}
fe:
restart: always
build:
context: ./cost-fe
image: cloudbaristaorg/mc-costopti-ui:edge
networks:
- mcmp_cost_network
ports:
- "8080:80"
- "80:80"
costcollector:
restart: always
build:
context: ./costCollector
image: cloudbaristaorg/mc-costopti-costcollector:edge
networks:
- mcmp_cost_network
ports:
Expand All @@ -48,8 +45,7 @@ services:
AWS_SECRET_ACCESS_KEY: ${AWS_SECRET_ACCESS_KEY}
costprocessor:
restart: always
build:
context: ./costProcessor
image: cloudbaristaorg/mc-costopti-costprocessor:edge
networks:
- mcmp_cost_network
ports:
Expand All @@ -64,8 +60,7 @@ services:
opti.alarm.url: ${ALARM_URL}
costselector:
restart: always
build:
context: ./costSelector
image: cloudbaristaorg/mc-costopti-costselector:edge
networks:
- mcmp_cost_network
ports:
Expand All @@ -77,8 +72,7 @@ services:
opti.alarm.url: ${ALARM_URL}
alarmservice:
restart: always
build:
context: ./AlarmService
image: cloudbaristaorg/mc-costopti-alarm:edge
networks:
- mcmp_cost_network
ports:
Expand All @@ -95,8 +89,7 @@ services:
spring.datasource.hikari.history.password: ${COST_DB_PW}
assetcollector:
restart: always
build:
context: ./assetCollector
image: cloudbaristaorg/mc-costopti-assetcollector:edge
networks:
- mcmp_cost_network
ports:
Expand All @@ -105,6 +98,7 @@ services:
spring.datasource.hikari.batch.jdbc-url: ${COST_DB_URL}
spring.datasource.hikari.batch.username: ${COST_DB_USERNM}
spring.datasource.hikari.batch.password: ${COST_DB_PW}
costopti.be.url: ${COST_BE_URL}
asset.collect.url: ${ASSET_MONITORING_SERVER}
assetCollectBatchCronSchedule: ${ASSET_COLLECT_BATCH_CRON_SCHEDULE}
networks:
Expand Down
Loading

0 comments on commit cd34d12

Please sign in to comment.