Skip to content
Snippets Groups Projects
Commit 0bbe0e67 authored by tranoris's avatar tranoris
Browse files

Merge branch 'develop' into parent-child-characteristics

parents 1b334cd7 9ec252d5
No related branches found
No related tags found
2 merge requests!12Merging 2024Q2_RC into main, creating 2024Q2 Release,!10Parent child characteristics
Pipeline #4051 failed
......@@ -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 triggerServiceActionQueue = false;
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, triggerServiceActionQueue );
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<Resource> rlist = new ArrayList<Resource>();
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, triggerServiceActionQueue );
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;
}
......
......@@ -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<Resource> rlist = new ArrayList<Resource>();
// 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;
// }
}
......@@ -183,8 +183,8 @@ public class ProcessOrderIntegrationTest {
assertThat(spec.getServiceSpecCharacteristic().size() ).isEqualTo(11);
assertThat(specCirros.getServiceSpecCharacteristic().size() ).isEqualTo(10);
assertThat(sorder.getOrderItem().stream().findFirst().get().getService().getServiceCharacteristic().size() ).isEqualTo(2);
assertThat(repositoryService.createProcessDefinitionQuery().count()).isEqualTo(14);
assertThat(repositoryService.createProcessDefinitionQuery().count()).isEqualTo(15);
assertThat(taskService.createTaskQuery().count()).isEqualTo(0);
assertThat( scmocked.getRequeestedDescriptor() ).isNull();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment