Skip to content

Commit

Permalink
Merge pull request #22 from m-cmp/main
Browse files Browse the repository at this point in the history
Project for 3.0.1 release
BSjaeyoung-kim authored Nov 19, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
2 parents 5917635 + cd34d12 commit d925e7d
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
@@ -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
@@ -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
```
@@ -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
```
Original file line number Diff line number Diff line change
@@ -52,6 +52,9 @@ public class AssetCollect {
@Autowired
private AssetCollectService assetCollectService;

@Autowired
private UpdateMetaBeforeAssetJob updateMetaBeforeAssetJob;

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

@@ -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;
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
@@ -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
@@ -2,8 +2,7 @@ version: '3'
services:
be:
restart: always
build:
context: ./BackEnd
image: cloudbaristaorg/mc-costopti-api:edge
networks:
- mcmp_cost_network
ports:
@@ -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:
@@ -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:
@@ -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:
@@ -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:
@@ -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:
@@ -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:
3,966 changes: 0 additions & 3,966 deletions mysql/init_cost_db.sql

This file was deleted.

7 changes: 7 additions & 0 deletions mysql/init_cost_db_ddl.sql
Original file line number Diff line number Diff line change
@@ -86,6 +86,10 @@ CREATE TABLE `cur_process_info` (
PRIMARY KEY (`csp`,`payer_account`,`collect_date`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

INSERT INTO cur_process_info (csp, payer_account, collect_date, object_key, certifed_fixed_yn, certifed_fixed_date)
VALUES ('AWS', 'mcmpcostopti', DATE_FORMAT(NOW() , '%Y%m'), NULL, 'N', NULL)
ON DUPLICATE KEY UPDATE collect_date = VALUES(collect_date);

-- cost.daily_abnormal_by_product definition

CREATE TABLE `daily_abnormal_by_product` (
@@ -205,6 +209,9 @@ CREATE TABLE `temp_cmp_user_info` (
`csp_account_id` varchar(100) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

INSERT INTO cost.temp_cmp_user_info(mcmp_user_id, csp_type, csp_account_id)
VALUES('mcmpcostopti', 'AWS', 'mcmpcostopti');

-- cost.temp_cmp_user_mail_receiver definition

CREATE TABLE `temp_cmp_user_mail_receiver` (

0 comments on commit d925e7d

Please sign in to comment.