|
|
@@ -5,13 +5,11 @@ import cn.reghao.autodop.dmaster.app.entity.AppBuilding;
|
|
|
import cn.reghao.autodop.dmaster.app.entity.AppDeploying;
|
|
|
import cn.reghao.autodop.dmaster.app.entity.AppRunning;
|
|
|
import cn.reghao.autodop.dmaster.app.entity.config.AppOrchestration;
|
|
|
-import cn.reghao.autodop.dmaster.app.entity.config.deploy.DeployConfig;
|
|
|
import cn.reghao.autodop.dmaster.app.repository.AppBuildingRepository;
|
|
|
import cn.reghao.autodop.dmaster.app.repository.AppDeployingRepository;
|
|
|
import cn.reghao.autodop.dmaster.app.repository.AppRunningRepository;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@@ -36,27 +34,31 @@ public class AppBuildService {
|
|
|
this.runningRepository = runningRepository;
|
|
|
}
|
|
|
|
|
|
- public void refreshing() {
|
|
|
+ public void refresh() {
|
|
|
refreshAppBuilding();
|
|
|
refreshAppDeploying();
|
|
|
refreshAppRunning();
|
|
|
}
|
|
|
|
|
|
+ public void refreshApp(AppOrchestration app) {
|
|
|
+ refreshAppBuilding(app);
|
|
|
+ refreshAppDeploying(app);
|
|
|
+ refreshAppRunning(app);
|
|
|
+ }
|
|
|
+
|
|
|
public void refreshAppBuilding() {
|
|
|
List<AppOrchestration> apps = appQuery.findAllByEnableIsTrue();
|
|
|
- List<AppBuilding> list = new ArrayList<>();
|
|
|
- for (AppOrchestration app : apps) {
|
|
|
- AppBuilding appBuilding = buildingRepository.findByAppId(app.getAppId());
|
|
|
- if (appBuilding == null) {
|
|
|
- list.add(new AppBuilding(app));
|
|
|
- } else {
|
|
|
- list.add(appBuilding.refresh(app));
|
|
|
- }
|
|
|
- }
|
|
|
- buildingRepository.saveAll(list);
|
|
|
+ apps.forEach(this::refreshAppBuilding);
|
|
|
}
|
|
|
|
|
|
- public void refreshAppBuilding(AppOrchestration app) {
|
|
|
+ /**
|
|
|
+ * 刷新应用构建列表
|
|
|
+ *
|
|
|
+ * @param
|
|
|
+ * @return
|
|
|
+ * @date 2021-06-18 下午5:24
|
|
|
+ */
|
|
|
+ private void refreshAppBuilding(AppOrchestration app) {
|
|
|
AppBuilding appBuilding = buildingRepository.findByAppId(app.getAppId());
|
|
|
if (appBuilding == null) {
|
|
|
appBuilding = new AppBuilding(app);
|
|
|
@@ -66,83 +68,84 @@ public class AppBuildService {
|
|
|
buildingRepository.save(appBuilding);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 刷新应用部署列表
|
|
|
+ *
|
|
|
+ * @param
|
|
|
+ * @return
|
|
|
+ * @date 2021-06-18 下午5:25
|
|
|
+ */
|
|
|
public void refreshAppDeploying() {
|
|
|
List<AppOrchestration> apps = appQuery.findAllByEnableIsTrue().stream()
|
|
|
.filter(app -> !app.getDeployConfigs().isEmpty())
|
|
|
+ // TODO 使用 peek
|
|
|
+ //.peek()
|
|
|
.collect(Collectors.toList());
|
|
|
-
|
|
|
- List<AppDeploying> list = new ArrayList<>();
|
|
|
- for (AppOrchestration app : apps) {
|
|
|
- String appId = app.getAppId();
|
|
|
- List<DeployConfig> deployConfigs = app.getDeployConfigs();
|
|
|
- for (DeployConfig deployConfig : deployConfigs) {
|
|
|
- String machineId = deployConfig.getMachineId();
|
|
|
- AppDeploying appDeploying = deployingRepository.findByAppIdAndMachineId(appId, machineId);
|
|
|
- if (appDeploying == null) {
|
|
|
- appDeploying = new AppDeploying(app, deployConfig);
|
|
|
- } else {
|
|
|
- appDeploying.refresh(app.getAppName(), deployConfig.getMachineIpv4());
|
|
|
- }
|
|
|
- list.add(appDeploying);
|
|
|
- }
|
|
|
- }
|
|
|
- deployingRepository.saveAll(list);
|
|
|
+ apps.forEach(this::refreshAppDeploying);
|
|
|
}
|
|
|
|
|
|
- public void refreshAppDeploying(AppOrchestration app) {
|
|
|
+ private void refreshAppDeploying(AppOrchestration app) {
|
|
|
String appId = app.getAppId();
|
|
|
- List<DeployConfig> deployConfigs = app.getDeployConfigs();
|
|
|
- List<AppDeploying> list = new ArrayList<>();
|
|
|
- for (DeployConfig deployConfig : deployConfigs) {
|
|
|
- String machineId = deployConfig.getMachineId();
|
|
|
- AppDeploying appDeploying = deployingRepository.findByAppIdAndMachineId(appId, machineId);
|
|
|
- if (appDeploying == null) {
|
|
|
- appDeploying = new AppDeploying(app, deployConfig);
|
|
|
- } else {
|
|
|
- appDeploying.refresh(app.getAppName(), deployConfig.getMachineIpv4());
|
|
|
- }
|
|
|
- list.add(appDeploying);
|
|
|
- }
|
|
|
+ List<AppDeploying> list = app.getDeployConfigs().stream()
|
|
|
+ .map(deployConfig -> {
|
|
|
+ String machineId = deployConfig.getMachineId();
|
|
|
+ AppDeploying appDeploying = deployingRepository.findByAppIdAndMachineId(appId, machineId);
|
|
|
+ if (appDeploying == null) {
|
|
|
+ appDeploying = new AppDeploying(app, deployConfig);
|
|
|
+ } else {
|
|
|
+ appDeploying.refresh(app.getAppName(), deployConfig.getMachineIpv4());
|
|
|
+ }
|
|
|
+ return appDeploying;
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList());
|
|
|
deployingRepository.saveAll(list);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 刷新应用状态列表
|
|
|
+ *
|
|
|
+ * @param
|
|
|
+ * @return
|
|
|
+ * @date 2021-06-18 下午5:29
|
|
|
+ */
|
|
|
public void refreshAppRunning() {
|
|
|
List<AppOrchestration> apps = appQuery.findAllByEnableIsTrue().stream()
|
|
|
.filter(app -> !app.getDeployConfigs().isEmpty())
|
|
|
.collect(Collectors.toList());
|
|
|
+ apps.forEach(this::refreshAppRunning);
|
|
|
+ }
|
|
|
|
|
|
- List<AppRunning> list = new ArrayList<>();
|
|
|
- for (AppOrchestration app : apps) {
|
|
|
- String appId = app.getAppId();
|
|
|
- List<DeployConfig> deployConfigs = app.getDeployConfigs();
|
|
|
- for (DeployConfig deployConfig : deployConfigs) {
|
|
|
- String machineId = deployConfig.getMachineId();
|
|
|
- AppRunning appRunning = runningRepository.findByAppIdAndMachineId(appId, machineId);
|
|
|
- if (appRunning == null) {
|
|
|
- appRunning = new AppRunning(app, deployConfig);
|
|
|
- } else {
|
|
|
- appRunning.refresh(app.getAppName(), deployConfig.getMachineIpv4());
|
|
|
- }
|
|
|
- list.add(appRunning);
|
|
|
- }
|
|
|
- }
|
|
|
+ private void refreshAppRunning(AppOrchestration app) {
|
|
|
+ String appId = app.getAppId();
|
|
|
+ List<AppRunning> list = app.getDeployConfigs().stream()
|
|
|
+ .map(deployConfig -> {
|
|
|
+ String machineId = deployConfig.getMachineId();
|
|
|
+ AppRunning appRunning = runningRepository.findByAppIdAndMachineId(appId, machineId);
|
|
|
+ if (appRunning == null) {
|
|
|
+ appRunning = new AppRunning(app, deployConfig);
|
|
|
+ } else {
|
|
|
+ appRunning.refresh(app.getAppName(), deployConfig.getMachineIpv4());
|
|
|
+ }
|
|
|
+ return appRunning;
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList());
|
|
|
runningRepository.saveAll(list);
|
|
|
}
|
|
|
|
|
|
- public void refreshAppRunning(AppOrchestration app) {
|
|
|
- String appId = app.getAppId();
|
|
|
- List<DeployConfig> deployConfigs = app.getDeployConfigs();
|
|
|
- List<AppRunning> list = new ArrayList<>();
|
|
|
- for (DeployConfig deployConfig : deployConfigs) {
|
|
|
- String machineId = deployConfig.getMachineId();
|
|
|
- AppRunning appRunning = runningRepository.findByAppIdAndMachineId(appId, machineId);
|
|
|
- if (appRunning == null) {
|
|
|
- appRunning = new AppRunning(app, deployConfig);
|
|
|
- } else {
|
|
|
- appRunning.refresh(app.getAppName(), deployConfig.getMachineIpv4());
|
|
|
- }
|
|
|
- list.add(appRunning);
|
|
|
+ public void delete(String appId) {
|
|
|
+ AppBuilding appBuilding = buildingRepository.findByAppId(appId);
|
|
|
+ if (appBuilding != null) {
|
|
|
+ buildingRepository.delete(appBuilding);
|
|
|
+ }
|
|
|
+
|
|
|
+ List<AppDeploying> appDeployings = deployingRepository.findByAppId(appId);
|
|
|
+ if (!appDeployings.isEmpty()) {
|
|
|
+ deployingRepository.deleteAll(appDeployings);
|
|
|
+ }
|
|
|
+
|
|
|
+ List<AppRunning> appRunnings = runningRepository.findByAppId(appId);
|
|
|
+ if (!appRunnings.isEmpty()) {
|
|
|
+ runningRepository.deleteAll(appRunnings);
|
|
|
}
|
|
|
- runningRepository.saveAll(list);
|
|
|
}
|
|
|
}
|