2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.dcaegen2.platform.mod.web.service.microserviceinstance;
23 import org.onap.dcaegen2.platform.mod.model.deploymentartifact.DeploymentArtifact;
24 import org.onap.dcaegen2.platform.mod.model.deploymentartifact.DeploymentArtifactStatus;
25 import org.onap.dcaegen2.platform.mod.model.microserviceinstance.MsInstance;
26 import org.onap.dcaegen2.platform.mod.model.microserviceinstance.MsInstanceStatus;
27 import org.onap.dcaegen2.platform.mod.web.service.deploymentartifact.DeploymentArtifactService;
28 import lombok.extern.slf4j.Slf4j;
29 import org.springframework.beans.factory.annotation.Autowired;
30 import org.springframework.stereotype.Component;
32 import java.util.List;
35 * A class responsible for handling status changes of Ms Instances
39 public class MsInstanceStatusChangeHandler {
42 private MsInstanceService msInstanceService;
45 private DeploymentArtifactService deploymentArtifactService;
47 public void setMsInstanceService(MsInstanceService msInstanceService) {
48 this.msInstanceService = msInstanceService;
51 public void setDeploymentArtifactService(DeploymentArtifactService deploymentArtifactService) {
52 this.deploymentArtifactService = deploymentArtifactService;
55 public void updateStatusBasedOnDeploymentArtifactsStatuses(MsInstance msInstance) {
56 log.info("Checking if any Status change required for msInstance {}...", msInstance);
57 List<DeploymentArtifact> artifacts = deploymentArtifactService.findByMsInstanceId(msInstance.getId());
58 MsInstanceStatus newStatus = getValidStatusBasedOnArtifacts(artifacts);
59 msInstance.setStatus(newStatus);
60 log.info("Changed Status to {}", newStatus);
63 private MsInstanceStatus getValidStatusBasedOnArtifacts(List<DeploymentArtifact> artifacts) {
64 if(atLeastOneArtifactHasDevCompleteStatus(artifacts)){
65 return MsInstanceStatus.DEV_COMPLETE;
67 return MsInstanceStatus.IN_DEV;
70 private boolean atLeastOneArtifactHasDevCompleteStatus(List<DeploymentArtifact> artifacts) {
73 .anyMatch(artifact -> artifact.getStatus() == DeploymentArtifactStatus.DEV_COMPLETE);