From ca553a4a97144d6a9759e793a227e4b87825bdd1 Mon Sep 17 00:00:00 2001 From: Christos Tranoris Date: Wed, 10 Jan 2024 17:46:12 +0200 Subject: [PATCH] fix for #13 --- ...CROrchestrationCheckDeploymentService.java | 116 ++++++------------ .../osom/management/OrderCompleteService.java | 65 ++++++++-- 2 files changed, 90 insertions(+), 91 deletions(-) diff --git a/src/main/java/org/etsi/osl/osom/management/CROrchestrationCheckDeploymentService.java b/src/main/java/org/etsi/osl/osom/management/CROrchestrationCheckDeploymentService.java index d13ff59..bb6182e 100644 --- a/src/main/java/org/etsi/osl/osom/management/CROrchestrationCheckDeploymentService.java +++ b/src/main/java/org/etsi/osl/osom/management/CROrchestrationCheckDeploymentService.java @@ -19,8 +19,14 @@ */ package org.etsi.osl.osom.management; +import java.time.OffsetDateTime; +import java.time.ZoneOffset; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.etsi.osl.tmf.common.model.service.Note; import org.etsi.osl.tmf.common.model.service.ResourceRef; import org.etsi.osl.tmf.common.model.service.ServiceStateType; import org.etsi.osl.tmf.ri639.model.Resource; @@ -29,6 +35,7 @@ import org.etsi.osl.tmf.sim638.model.ServiceUpdate; import org.flowable.engine.delegate.DelegateExecution; import org.flowable.engine.delegate.JavaDelegate; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import jakarta.validation.Valid; @@ -39,6 +46,10 @@ public class CROrchestrationCheckDeploymentService implements JavaDelegate { private static final transient Log logger = LogFactory.getLog(CROrchestrationCheckDeploymentService.class.getName()); + + @Value("${spring.application.name}") + private String compname; + @Autowired private ServiceOrderManager serviceOrderManager; @@ -62,96 +73,43 @@ public class CROrchestrationCheckDeploymentService implements JavaDelegate { return; } - execution.setVariable("serviceDeploymentFinished", Boolean.FALSE ); - ServiceUpdate supd = new ServiceUpdate(); boolean propagateToSO = false; //retrieve the related supporting resource by id and check its status //ResourceRef supresourceRef = aService.getSupportingResource().stream().findFirst().get();//we assume for now we have only one related resource - @Valid - ServiceStateType nextState = aService.getState() ; - boolean allActive = aService.getSupportingResource().size() > 0 ; - boolean allTerminated = aService.getSupportingResource().size() > 0 ; - boolean existsInactive=false; - boolean existsTerminated=false; - boolean existsReserved=false; - for ( ResourceRef supresourceRef : aService.getSupportingResource()) { - Resource res = serviceOrderManager.retrieveResource( supresourceRef.getId() ); - if ( res == null ) { - supd.setState( ServiceStateType.TERMINATED); - execution.setVariable("serviceDeploymentFinished", Boolean.TRUE); - Service serviceResult = serviceOrderManager.updateService( aService.getId(), supd, propagateToSO ); - return; - } - - - - if ( res.getResourceStatus() != null ) { - switch (res.getResourceStatus()) { - case AVAILABLE: { - nextState = ServiceStateType.ACTIVE; - break; - } - case STANDBY: { - nextState = ServiceStateType.RESERVED; - break; - } - case SUSPENDED: { - nextState = ServiceStateType.INACTIVE; - break; - } - case RESERVED: { - nextState = ServiceStateType.RESERVED; - break; - } - case UNKNOWN: { - if (aService.getState().equals( ServiceStateType.ACTIVE )) { - nextState = ServiceStateType.TERMINATED; - } - break; - } - case ALARM: { - nextState = ServiceStateType.INACTIVE; - break; - } - default: - throw new IllegalArgumentException("Unexpected value: " + res.getResourceStatus()); - } - } - - allActive = allActive && nextState == ServiceStateType.ACTIVE; - allTerminated = allTerminated && nextState == ServiceStateType.TERMINATED; - existsInactive = existsInactive || nextState == ServiceStateType.INACTIVE; - existsTerminated = existsTerminated || nextState == ServiceStateType.TERMINATED; - existsReserved = existsReserved || nextState == ServiceStateType.RESERVED; - - + List rlist = new ArrayList(); + for (ResourceRef rref : aService.getSupportingResource()) { + Resource res = serviceOrderManager.retrieveResource(rref.getId()); + + if ( res == null ) { + supd.setState( ServiceStateType.TERMINATED); + execution.setVariable("serviceDeploymentFinished", Boolean.TRUE); + Service serviceResult = serviceOrderManager.updateService( aService.getId(), supd, propagateToSO ); + return; + } + rlist.add(res); + } + + ServiceStateType nextState = aService.findNextStateBasedOnSupportingResources(rlist); + supd.setState( nextState ); + Note n = new Note(); + n.setText("Service Status Changed to: " + nextState); + n.setAuthor(compname); + n.setDate(OffsetDateTime.now(ZoneOffset.UTC).toString()); + supd.addNoteItem(n); + + aService = serviceOrderManager.updateService( aService.getId(), supd, propagateToSO ); - - if ( allActive ) { - supd.setState( ServiceStateType.ACTIVE ); - } else if ( allTerminated ) { - supd.setState( ServiceStateType.TERMINATED ); - } else if ( existsInactive ) { - supd.setState( ServiceStateType.INACTIVE ); - } else if ( existsReserved ) { - supd.setState( ServiceStateType.RESERVED ); - } else if ( existsTerminated ) { - supd.setState( ServiceStateType.INACTIVE ); - } - - Service serviceResult = serviceOrderManager.updateService( aService.getId(), supd, propagateToSO ); - - if ( serviceResult!= null ) { - if ( serviceResult.getState().equals(ServiceStateType.ACTIVE) - || serviceResult.getState().equals(ServiceStateType.TERMINATED)) { + if ( aService!= null ) { + if ( aService.getState().equals(ServiceStateType.ACTIVE) + || aService.getState().equals(ServiceStateType.TERMINATED)) { - logger.info("Deployment Status OK. Service state = " + serviceResult.getState() ); + logger.info("Deployment Status OK. Service state = " + aService.getState() ); execution.setVariable("serviceDeploymentFinished", Boolean.TRUE); return; } diff --git a/src/main/java/org/etsi/osl/osom/management/OrderCompleteService.java b/src/main/java/org/etsi/osl/osom/management/OrderCompleteService.java index 7b37307..8f39cd0 100644 --- a/src/main/java/org/etsi/osl/osom/management/OrderCompleteService.java +++ b/src/main/java/org/etsi/osl/osom/management/OrderCompleteService.java @@ -21,13 +21,17 @@ package org.etsi.osl.osom.management; import java.time.OffsetDateTime; import java.time.ZoneOffset; +import java.util.ArrayList; +import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.etsi.osl.tmf.common.model.service.Note; import org.etsi.osl.tmf.common.model.service.ResourceRef; import org.etsi.osl.tmf.common.model.service.ServiceRef; import org.etsi.osl.tmf.common.model.service.ServiceStateType; +import org.etsi.osl.tmf.ri639.model.Resource; import org.etsi.osl.tmf.sim638.model.Service; +import org.etsi.osl.tmf.sim638.model.ServiceUpdate; import org.etsi.osl.tmf.so641.model.ServiceOrder; import org.etsi.osl.tmf.so641.model.ServiceOrderItem; import org.etsi.osl.tmf.so641.model.ServiceOrderStateType; @@ -125,6 +129,20 @@ public class OrderCompleteService implements JavaDelegate { if ( soi.getService().getSupportingService() != null) { for (ServiceRef sr : soi.getService().getSupportingService()) { Service srv = serviceOrderManager.retrieveService( sr.getId() ); +// +// if ( srv.getState().equals(ServiceStateType.RESERVED) +// || srv.getState().equals(ServiceStateType.INACTIVE) +// || srv.getState().equals(ServiceStateType.DESIGNED) ){ +// try { +// if ( srv.getSupportingResource()!=null && srv.getSupportingResource().size()>0 ) { +// srv = reEvaluateServiceState( srv ); +// +// } +// } catch (Exception e) { +// +// } +// } + existsReserved = existsReserved || srv.getState().equals(ServiceStateType.RESERVED ); existsInactive = existsInactive || srv.getState().equals(ServiceStateType.INACTIVE ); existsDesigned = existsDesigned || srv.getState().equals(ServiceStateType.DESIGNED ); @@ -136,18 +154,7 @@ public class OrderCompleteService implements JavaDelegate { } - if ( soi.getService().getSupportingResource() != null) { - for (ResourceRef rr : soi.getService().getSupportingResource()) { - Service srv = serviceOrderManager.retrieveService( rr.getId() ); - existsReserved = existsReserved || srv.getState().equals(ServiceStateType.RESERVED ); - existsInactive = existsInactive || srv.getState().equals(ServiceStateType.INACTIVE ); - existsDesigned = existsDesigned || srv.getState().equals(ServiceStateType.DESIGNED ); - existsActive = existsActive || srv.getState().equals(ServiceStateType.ACTIVE ); - existsTerminated = existsTerminated || srv.getState().equals(ServiceStateType.TERMINATED ); - allTerminated = allTerminated && srv.getState().equals(ServiceStateType.TERMINATED ); - allActive = allActive && srv.getState().equals(ServiceStateType.ACTIVE ); - } - } + @Valid ServiceStateType sserviceState = soi.getService().getState(); @@ -220,4 +227,38 @@ public class OrderCompleteService implements JavaDelegate { } +// /** +// * @param srv +// * @return +// */ +// private Service reEvaluateServiceState(Service aService) { +// +// List rlist = new ArrayList(); +// for (ResourceRef rref : aService.getSupportingResource()) { +// Resource res = serviceOrderManager.retrieveResource(rref.getId()); +// +// if ( res != null ) { +// rlist.add(res); +// } +// } +// +// ServiceStateType curState = aService.getState(); +// +// ServiceStateType nextState = aService.findNextStateBasedOnSupportingResources(rlist); +// if ( !curState.equals(nextState)) { +// ServiceUpdate supd = new ServiceUpdate(); +// supd.setState( nextState ); +// Note n = new Note(); +// n.setText("Service Status Changed via OrderCompleteService method to: " + nextState); +// n.setAuthor(compname); +// n.setDate(OffsetDateTime.now(ZoneOffset.UTC).toString()); +// supd.addNoteItem(n); +// +// Service serviceResult = serviceOrderManager.updateService( aService.getId(), supd, false ); +// return serviceResult; +// +// } +// return aService; +// } + } -- GitLab