File src/main/java/com/kingfisher/deployment/audit/data/builder/DeploymentStatusBuidler.java changed (mode: 100644) (index cc938fb..ec099ec) |
... |
... |
package com.kingfisher.deployment.audit.data.builder; |
3 |
3 |
import java.text.ParseException;
|
import java.text.ParseException;
|
4 |
4 |
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
5 |
5 |
import java.util.ArrayList;
|
import java.util.ArrayList;
|
|
6 |
|
import java.util.Collections;
|
6 |
7 |
import java.util.Date;
|
import java.util.Date;
|
7 |
8 |
import java.util.List;
|
import java.util.List;
|
8 |
9 |
|
|
|
... |
... |
import com.kingfisher.deployment.audit.model.JenkinsDeploymentStatus; |
24 |
25 |
import com.kingfisher.deployment.audit.repository.InstanceRepository;
|
import com.kingfisher.deployment.audit.repository.InstanceRepository;
|
25 |
26 |
import com.kingfisher.deployment.audit.rest.client.IIBRestClient;
|
import com.kingfisher.deployment.audit.rest.client.IIBRestClient;
|
26 |
27 |
import com.kingfisher.deployment.audit.security.PasswordCodec;
|
import com.kingfisher.deployment.audit.security.PasswordCodec;
|
27 |
|
import com.kingfisher.deployment.audit.test.util.IntegrationTestUtil;
|
|
28 |
28 |
|
|
29 |
29 |
@Component
|
@Component
|
30 |
30 |
public class DeploymentStatusBuidler {
|
public class DeploymentStatusBuidler {
|
|
... |
... |
public class DeploymentStatusBuidler { |
48 |
48 |
String createdByProcess = jenkinsDeploymentStatus.getCreatedByProcess();
|
String createdByProcess = jenkinsDeploymentStatus.getCreatedByProcess();
|
49 |
49 |
|
|
50 |
50 |
Instance instance = instanceRepository.findByInstanceName(instanceName);
|
Instance instance = instanceRepository.findByInstanceName(instanceName);
|
51 |
|
IIBDeploymentStatus iibDeploymentStatus = iibRestClient.getDeployemntProperties(integrationServer, applicationName, instance.getHost(), instance.getApiPort(), instance.getApiUsername(), passwordCodec.decrypt(instance.getApiPassword()));
|
|
|
51 |
|
IIBDeploymentStatus iibDeploymentStatus = iibRestClient.getDeployemntProperties(integrationServer,
|
|
52 |
|
applicationName, instance.getHost(), instance.getApiPort(), instance.getApiUsername(),
|
|
53 |
|
passwordCodec.decrypt(instance.getApiPassword()));
|
52 |
54 |
|
|
53 |
55 |
Date barDeploymentTime = getBarDeploymentTime(iibDeploymentStatus);
|
Date barDeploymentTime = getBarDeploymentTime(iibDeploymentStatus);
|
54 |
56 |
Date barModifyTime = getBarModifyTime(iibDeploymentStatus);
|
Date barModifyTime = getBarModifyTime(iibDeploymentStatus);
|
|
... |
... |
public class DeploymentStatusBuidler { |
58 |
60 |
|
|
59 |
61 |
Date createdTime = new Date();
|
Date createdTime = new Date();
|
60 |
62 |
|
|
61 |
|
return new Deployment(applicationName, barfileName, environment, instanceName, integrationServer, barDeploymentTime, createdTime, barModifyTime, barReleaseId, barChecksum, deployedByUserName, deployedByUserId, createdByProcess);
|
|
|
63 |
|
return new Deployment(applicationName, barfileName, environment, instanceName, integrationServer,
|
|
64 |
|
barDeploymentTime, createdTime, barModifyTime, barReleaseId, barChecksum, deployedByUserName,
|
|
65 |
|
deployedByUserId, createdByProcess);
|
62 |
66 |
}
|
}
|
63 |
67 |
|
|
64 |
68 |
public List<Deployment> getSnapshotFromIIB(final String tier) throws DeploymentAuditException {
|
public List<Deployment> getSnapshotFromIIB(final String tier) throws DeploymentAuditException {
|
65 |
69 |
List<Deployment> iibList = new ArrayList<>();
|
List<Deployment> iibList = new ArrayList<>();
|
66 |
70 |
List<Instance> instances = instanceRepository.findByTier(tier);
|
List<Instance> instances = instanceRepository.findByTier(tier);
|
67 |
71 |
for (Instance instance : instances) {
|
for (Instance instance : instances) {
|
68 |
|
IntegrationServers integrationServers = iibRestClient.getIntegrationServers(instance.getHost(), instance.getApiPort(), instance.getApiUsername(), passwordCodec.decrypt(instance.getApiPassword()));
|
|
|
72 |
|
IntegrationServers integrationServers = iibRestClient.getIntegrationServers(instance.getHost(),
|
|
73 |
|
instance.getApiPort(), instance.getApiUsername(), passwordCodec.decrypt(instance.getApiPassword()));
|
69 |
74 |
for (IntegrationServer integrationServer : integrationServers.getExecutionGroup()) {
|
for (IntegrationServer integrationServer : integrationServers.getExecutionGroup()) {
|
70 |
|
Applications applications = iibRestClient.getApplications(integrationServer.getName(), instance.getHost(), instance.getApiPort(), instance.getApiUsername(), passwordCodec.decrypt(instance.getApiPassword()));
|
|
|
75 |
|
Applications applications = iibRestClient.getApplications(integrationServer.getName(),
|
|
76 |
|
instance.getHost(), instance.getApiPort(), instance.getApiUsername(),
|
|
77 |
|
passwordCodec.decrypt(instance.getApiPassword()));
|
71 |
78 |
for (Application application : applications.getApplication()) {
|
for (Application application : applications.getApplication()) {
|
72 |
|
IIBDeploymentStatus iibDeploymentStatus = iibRestClient.getDeployemntProperties(integrationServer.getName(), application.getName(), instance.getHost(), instance.getApiPort(), instance.getApiUsername(), passwordCodec.decrypt(instance.getApiPassword()));
|
|
73 |
|
iibList.add(new Deployment(application.getName(), getBarFileName(iibDeploymentStatus), instance.getTier(), instance.getInstanceName(), integrationServer.getName(), getBarDeploymentTime(iibDeploymentStatus), new Date(), getBarModifyTime(iibDeploymentStatus), getBarReleaseId(iibDeploymentStatus), getBarCheckSum(iibDeploymentStatus), "api", "api", "snapshot"));
|
|
|
79 |
|
IIBDeploymentStatus iibDeploymentStatus = iibRestClient.getDeployemntProperties(
|
|
80 |
|
integrationServer.getName(), application.getName(), instance.getHost(),
|
|
81 |
|
instance.getApiPort(), instance.getApiUsername(),
|
|
82 |
|
passwordCodec.decrypt(instance.getApiPassword()));
|
|
83 |
|
iibList.add(new Deployment(application.getName(), getBarFileName(iibDeploymentStatus),
|
|
84 |
|
instance.getTier(), instance.getInstanceName(), integrationServer.getName(),
|
|
85 |
|
getBarDeploymentTime(iibDeploymentStatus), new Date(),
|
|
86 |
|
getBarModifyTime(iibDeploymentStatus), getBarReleaseId(iibDeploymentStatus),
|
|
87 |
|
getBarCheckSum(iibDeploymentStatus), "api", "api", "snapshot"));
|
74 |
88 |
}
|
}
|
75 |
89 |
}
|
}
|
76 |
90 |
}
|
}
|
77 |
91 |
return iibList;
|
return iibList;
|
78 |
92 |
}
|
}
|
79 |
93 |
|
|
80 |
|
public void compareDeploymentsAndRectify(final List<Deployment> iibList, final List<Deployment> dbList) {
|
|
|
94 |
|
public List<Deployment> compareDeploymentsAndRectify(final List<Deployment> iibList,
|
|
95 |
|
final List<Deployment> dbList) {
|
|
96 |
|
List<Deployment> deploymentToBeUpdated = new ArrayList<>();
|
81 |
97 |
List<IndexedDeployment> iibIndexedList = indexDeployment(iibList);
|
List<IndexedDeployment> iibIndexedList = indexDeployment(iibList);
|
82 |
98 |
List<IndexedDeployment> dbIndexedList = indexDeployment(dbList);
|
List<IndexedDeployment> dbIndexedList = indexDeployment(dbList);
|
83 |
|
|
|
|
99 |
|
Collections.sort(iibIndexedList);
|
|
100 |
|
Collections.sort(dbIndexedList);
|
|
101 |
|
|
|
102 |
|
for (IndexedDeployment iibDeployment : iibIndexedList) {
|
|
103 |
|
boolean deploymentMatched = false;
|
|
104 |
|
IndexedDeployment matchedDBDeployment = null;
|
|
105 |
|
for (IndexedDeployment dbDeployment : dbIndexedList) {
|
|
106 |
|
if (iibDeployment.getIndex().equals(dbDeployment.getIndex())) {
|
|
107 |
|
deploymentMatched = true;
|
|
108 |
|
matchedDBDeployment = dbDeployment;
|
|
109 |
|
|
|
110 |
|
if (!iibDeployment.getDeployment().getBarDeploymentTime()
|
|
111 |
|
.equals(dbDeployment.getDeployment().getBarDeploymentTime())) {
|
|
112 |
|
dbDeployment.getDeployment().setExcludeFromReport(true);
|
|
113 |
|
deploymentToBeUpdated.add(dbDeployment.getDeployment());
|
|
114 |
|
deploymentToBeUpdated.add(iibDeployment.getDeployment());
|
|
115 |
|
}
|
|
116 |
|
|
|
117 |
|
break;
|
|
118 |
|
}
|
|
119 |
|
if (iibDeployment.compareTo(dbDeployment) < 0)
|
|
120 |
|
break;
|
|
121 |
|
}
|
|
122 |
|
if (deploymentMatched) {
|
|
123 |
|
dbIndexedList.remove(matchedDBDeployment);
|
|
124 |
|
} else {
|
|
125 |
|
deploymentToBeUpdated.add(iibDeployment.getDeployment());
|
|
126 |
|
}
|
|
127 |
|
}
|
|
128 |
|
|
|
129 |
|
for (IndexedDeployment dbDeployment : dbIndexedList) {
|
|
130 |
|
dbDeployment.getDeployment().setExcludeFromReport(true);
|
|
131 |
|
dbDeployment.getDeployment().setBarDeleted(true);
|
|
132 |
|
deploymentToBeUpdated.add(dbDeployment.getDeployment());
|
|
133 |
|
}
|
|
134 |
|
|
|
135 |
|
return deploymentToBeUpdated;
|
84 |
136 |
}
|
}
|
85 |
137 |
|
|
86 |
138 |
private List<IndexedDeployment> indexDeployment(final List<Deployment> deployments) {
|
private List<IndexedDeployment> indexDeployment(final List<Deployment> deployments) {
|
File src/main/java/com/kingfisher/deployment/audit/model/Deployment.java changed (mode: 100644) (index 7f7088a..33de171) |
... |
... |
public class Deployment { |
70 |
70 |
public Deployment() {
|
public Deployment() {
|
71 |
71 |
}
|
}
|
72 |
72 |
|
|
73 |
|
public Deployment(String applicationName, String barfileName, String environment, String instanceName, String integrationServer, Date barDeploymentTime, Date createdTime, Date barModifyTime, String barReleaseId, String barChecksum, String deployedByUserName, String deployedByUserId, String createdByProcess) {
|
|
|
73 |
|
public Deployment(String applicationName, String barfileName, String environment, String instanceName,
|
|
74 |
|
String integrationServer, Date barDeploymentTime, Date createdTime, Date barModifyTime, String barReleaseId,
|
|
75 |
|
String barChecksum, String deployedByUserName, String deployedByUserId, String createdByProcess) {
|
74 |
76 |
this.applicationName = applicationName;
|
this.applicationName = applicationName;
|
75 |
77 |
this.barfileName = barfileName;
|
this.barfileName = barfileName;
|
76 |
78 |
this.environment = environment;
|
this.environment = environment;
|
|
... |
... |
public class Deployment { |
206 |
208 |
this.excludeFromReport = excludeFromReport;
|
this.excludeFromReport = excludeFromReport;
|
207 |
209 |
}
|
}
|
208 |
210 |
|
|
|
211 |
|
public boolean isBarDeleted() {
|
|
212 |
|
return barDeleted;
|
|
213 |
|
}
|
|
214 |
|
|
|
215 |
|
public void setBarDeleted(boolean barDeleted) {
|
|
216 |
|
this.barDeleted = barDeleted;
|
|
217 |
|
}
|
|
218 |
|
|
209 |
219 |
@Override
|
@Override
|
210 |
220 |
public String toString() {
|
public String toString() {
|
211 |
|
return "Deployment [deploymentId=" + deploymentId + ", applicationName=" + applicationName + ", barfileName=" + barfileName + ", environment=" + environment + ", instanceName=" + instanceName + ", integrationServer=" + integrationServer + ", barDeploymentTime=" + barDeploymentTime + ", createdTime=" + createdTime + ", barModifyTime=" + barModifyTime + ", barReleaseId=" + barReleaseId + ", barChecksum=" + barChecksum + ", deployedByUserName=" + deployedByUserName + ", deployedByUserId=" + deployedByUserId + ", createdByProcess=" + createdByProcess + ", barDeleted=" + barDeleted + ", excludeFromReport=" + excludeFromReport + "]";
|
|
|
221 |
|
return "Deployment [deploymentId=" + deploymentId + ", applicationName=" + applicationName + ", barfileName="
|
|
222 |
|
+ barfileName + ", environment=" + environment + ", instanceName=" + instanceName
|
|
223 |
|
+ ", integrationServer=" + integrationServer + ", barDeploymentTime=" + barDeploymentTime
|
|
224 |
|
+ ", createdTime=" + createdTime + ", barModifyTime=" + barModifyTime + ", barReleaseId=" + barReleaseId
|
|
225 |
|
+ ", barChecksum=" + barChecksum + ", deployedByUserName=" + deployedByUserName + ", deployedByUserId="
|
|
226 |
|
+ deployedByUserId + ", createdByProcess=" + createdByProcess + ", barDeleted=" + barDeleted
|
|
227 |
|
+ ", excludeFromReport=" + excludeFromReport + "]";
|
212 |
228 |
}
|
}
|
213 |
229 |
|
|
214 |
230 |
}
|
}
|
File src/main/java/com/kingfisher/deployment/audit/service/DeploymentAuditService.java changed (mode: 100644) (index b7133ef..b7567fc) |
... |
... |
import org.springframework.stereotype.Service; |
14 |
14 |
import com.kingfisher.deployment.audit.data.builder.DeploymentStatusBuidler;
|
import com.kingfisher.deployment.audit.data.builder.DeploymentStatusBuidler;
|
15 |
15 |
import com.kingfisher.deployment.audit.exception.model.DeploymentAuditException;
|
import com.kingfisher.deployment.audit.exception.model.DeploymentAuditException;
|
16 |
16 |
import com.kingfisher.deployment.audit.model.Deployment;
|
import com.kingfisher.deployment.audit.model.Deployment;
|
17 |
|
import com.kingfisher.deployment.audit.model.IndexedDeployment;
|
|
18 |
17 |
import com.kingfisher.deployment.audit.model.JenkinsDeploymentStatus;
|
import com.kingfisher.deployment.audit.model.JenkinsDeploymentStatus;
|
19 |
18 |
import com.kingfisher.deployment.audit.report.builder.ExcelReportBuilder;
|
import com.kingfisher.deployment.audit.report.builder.ExcelReportBuilder;
|
20 |
19 |
import com.kingfisher.deployment.audit.repository.DeploymentRepository;
|
import com.kingfisher.deployment.audit.repository.DeploymentRepository;
|
|
... |
... |
public class DeploymentAuditService { |
65 |
64 |
* @return
|
* @return
|
66 |
65 |
* @throws DeploymentAuditException
|
* @throws DeploymentAuditException
|
67 |
66 |
*/
|
*/
|
68 |
|
private Map<String, List<Deployment>> prepareDataForApplication(String application, String referenceEnv, List<String> reportingEnvs) throws DeploymentAuditException {
|
|
|
67 |
|
private Map<String, List<Deployment>> prepareDataForApplication(String application, String referenceEnv,
|
|
68 |
|
List<String> reportingEnvs) throws DeploymentAuditException {
|
69 |
69 |
Map<String, List<Deployment>> latestDeploymentsInEnvironmentForApplication = new LinkedHashMap<>();
|
Map<String, List<Deployment>> latestDeploymentsInEnvironmentForApplication = new LinkedHashMap<>();
|
70 |
|
latestDeploymentsInEnvironmentForApplication.put(referenceEnv, deploymentRepository.findLatestDeploymentByApplicationNameAndEnvironment(referenceEnv, application));
|
|
|
70 |
|
latestDeploymentsInEnvironmentForApplication.put(referenceEnv,
|
|
71 |
|
deploymentRepository.findLatestDeploymentByApplicationNameAndEnvironment(referenceEnv, application));
|
71 |
72 |
for (String reportingEnv : reportingEnvs)
|
for (String reportingEnv : reportingEnvs)
|
72 |
|
latestDeploymentsInEnvironmentForApplication.put(reportingEnv, deploymentRepository.findLatestDeploymentByApplicationNameAndEnvironment(reportingEnv, application));
|
|
|
73 |
|
latestDeploymentsInEnvironmentForApplication.put(reportingEnv, deploymentRepository
|
|
74 |
|
.findLatestDeploymentByApplicationNameAndEnvironment(reportingEnv, application));
|
73 |
75 |
return latestDeploymentsInEnvironmentForApplication;
|
return latestDeploymentsInEnvironmentForApplication;
|
74 |
76 |
}
|
}
|
75 |
77 |
|
|
|
... |
... |
public class DeploymentAuditService { |
81 |
83 |
* @return
|
* @return
|
82 |
84 |
* @throws DeploymentAuditException
|
* @throws DeploymentAuditException
|
83 |
85 |
*/
|
*/
|
84 |
|
public void recordDeployments(List<JenkinsDeploymentStatus> jenkinsDeploymentStatuses) throws DeploymentAuditException {
|
|
|
86 |
|
public void recordDeployments(List<JenkinsDeploymentStatus> jenkinsDeploymentStatuses)
|
|
87 |
|
throws DeploymentAuditException {
|
85 |
88 |
List<Deployment> deployments = new ArrayList<>();
|
List<Deployment> deployments = new ArrayList<>();
|
86 |
89 |
for (JenkinsDeploymentStatus jenkinsDeploymentStatus : jenkinsDeploymentStatuses) {
|
for (JenkinsDeploymentStatus jenkinsDeploymentStatus : jenkinsDeploymentStatuses) {
|
87 |
90 |
Deployment deployment = deploymentStatusBuidler.build(jenkinsDeploymentStatus);
|
Deployment deployment = deploymentStatusBuidler.build(jenkinsDeploymentStatus);
|
88 |
|
if (deploymentRepository.findByApplicationNameAndInstanceNameAndIntegrationServerAndBarDeploymentTime(deployment.getApplicationName(), deployment.getInstanceName(), deployment.getIntegrationServer(), deployment.getBarDeploymentTime()).equals(Optional.empty())) {
|
|
89 |
|
deploymentRepository.hideFromReport(deployment.getApplicationName(), deployment.getInstanceName(), deployment.getIntegrationServer());
|
|
|
91 |
|
if (deploymentRepository
|
|
92 |
|
.findByApplicationNameAndInstanceNameAndIntegrationServerAndBarDeploymentTime(
|
|
93 |
|
deployment.getApplicationName(), deployment.getInstanceName(),
|
|
94 |
|
deployment.getIntegrationServer(), deployment.getBarDeploymentTime())
|
|
95 |
|
.equals(Optional.empty())) {
|
|
96 |
|
deploymentRepository.hideFromReport(deployment.getApplicationName(), deployment.getInstanceName(),
|
|
97 |
|
deployment.getIntegrationServer());
|
90 |
98 |
deployments.add(deployment);
|
deployments.add(deployment);
|
91 |
99 |
}
|
}
|
92 |
100 |
}
|
}
|
|
... |
... |
public class DeploymentAuditService { |
105 |
113 |
public void createSnapshot(String tier) throws DeploymentAuditException {
|
public void createSnapshot(String tier) throws DeploymentAuditException {
|
106 |
114 |
List<Deployment> iibList = deploymentStatusBuidler.getSnapshotFromIIB(tier);
|
List<Deployment> iibList = deploymentStatusBuidler.getSnapshotFromIIB(tier);
|
107 |
115 |
List<Deployment> dbList = deploymentRepository.findAllInReport(tier);
|
List<Deployment> dbList = deploymentRepository.findAllInReport(tier);
|
108 |
|
deploymentStatusBuidler.compareDeploymentsAndRectify(iibList, dbList);
|
|
|
116 |
|
for (Deployment deployment : deploymentStatusBuidler.compareDeploymentsAndRectify(iibList, dbList)) {
|
|
117 |
|
deploymentRepository.save(deployment);
|
|
118 |
|
}
|
109 |
119 |
}
|
}
|
110 |
120 |
|
|
111 |
121 |
} |
} |