Skip to content
Snippets Groups Projects
Commit 12582fb8 authored by tranoris's avatar tranoris
Browse files

Fix for createServiceRefIf with characteristics

parent d7cd8ff4
No related branches found
No related tags found
2 merge requests!12Merging 2024Q2_RC into main, creating 2024Q2 Release,!10Parent child characteristics
Pipeline #4402 failed
...@@ -28,7 +28,7 @@ public class LCMRulesExecutorVariables { ...@@ -28,7 +28,7 @@ public class LCMRulesExecutorVariables {
private Service service; private Service service;
private List<String> compileDiagnosticErrors; private List<String> compileDiagnosticErrors;
private ServiceOrderManager serviceOrderManager; private ServiceOrderManager serviceOrderManager;
private Map<String, String> outParams; private Map<String, Map<String, String> > outParams;
/** /**
* @param spec * @param spec
...@@ -50,6 +50,7 @@ public class LCMRulesExecutorVariables { ...@@ -50,6 +50,7 @@ public class LCMRulesExecutorVariables {
this.service = serviceInstance; this.service = serviceInstance;
this.serviceOrderManager = aServiceOrderManager; this.serviceOrderManager = aServiceOrderManager;
this.compileDiagnosticErrors = new ArrayList<>(); this.compileDiagnosticErrors = new ArrayList<>();
this.outParams = new HashMap<String,String>();
this.outParams = new HashMap<>();
} }
} }
...@@ -938,7 +938,7 @@ public abstract class LcmBaseExecutor { ...@@ -938,7 +938,7 @@ public abstract class LcmBaseExecutor {
//createServiceRefIf("Bundle B", getServiceRefPropValue("BundleA", "state", "").equals("active")==true); //createServiceRefIf("Bundle B", getServiceRefPropValue("BundleA", "state", "").equals("active")==true);
public boolean createServiceRefIf(String serviceName, boolean b) { public boolean createServiceRefIf(String serviceName, boolean b, HashMap<String, String> charvals) {
logger.debug( String.format("createServiceRefwhen serviceName=%s = %s", serviceName, b ) ); logger.debug( String.format("createServiceRefwhen serviceName=%s = %s", serviceName, b ) );
...@@ -952,7 +952,8 @@ public abstract class LcmBaseExecutor { ...@@ -952,7 +952,8 @@ public abstract class LcmBaseExecutor {
if (serviceIDToCheckDependcy != null) { if (serviceIDToCheckDependcy != null) {
this.vars.getOutParams().put( serviceIDToCheckDependcy, Boolean.toString(b) ); charvals.put("_CREATESERVICEREF_", Boolean.toString(b));
this.vars.getOutParams().put( serviceIDToCheckDependcy, charvals );
} }
return false; return false;
......
...@@ -3,7 +3,9 @@ package org.etsi.osl.osom.management; ...@@ -3,7 +3,9 @@ package org.etsi.osl.osom.management;
import java.time.OffsetDateTime; import java.time.OffsetDateTime;
import java.time.ZoneOffset; import java.time.ZoneOffset;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.etsi.osl.osom.lcm.LCMRulesController; import org.etsi.osl.osom.lcm.LCMRulesController;
...@@ -96,9 +98,16 @@ public class CreateReservedService implements JavaDelegate { ...@@ -96,9 +98,16 @@ public class CreateReservedService implements JavaDelegate {
logger.debug("Retrieved Service ID:" + spec.getId()); logger.debug("Retrieved Service ID:" + spec.getId());
logger.debug("Retrieved Service Name:" + spec.getName()); logger.debug("Retrieved Service Name:" + spec.getName());
//this map contains as key the id of the serviceSpecs to be created
//and as value a Map of initial characteristics and their values
Map<String, Map<String,String>> tobeCreatedInitialCharValues = new HashMap<>();
if ( execution.getVariable("serviceSpecsToCreateInitialCharValues") != null ) {
tobeCreatedInitialCharValues = (Map<String, Map<String, String>>) execution.getVariable("serviceSpecsToCreateInitialCharValues");
}
//this is a main underlying service for the requested service (restriction) //this is a main underlying service for the requested service (restriction)
Service createdUnderlService = addServicesToVariables( spec, sor, soi, parentService ); Service createdUnderlService = addServicesToVariables( spec, sor, soi, parentService, tobeCreatedInitialCharValues );
soi.getService().setState( ServiceStateType.RESERVED ); soi.getService().setState( ServiceStateType.RESERVED );
soi.setState(ServiceOrderStateType.INPROGRESS); soi.setState(ServiceOrderStateType.INPROGRESS);
...@@ -145,11 +154,12 @@ public class CreateReservedService implements JavaDelegate { ...@@ -145,11 +154,12 @@ public class CreateReservedService implements JavaDelegate {
* @param servicesHandledByNFVOAutomated * @param servicesHandledByNFVOAutomated
* @param servicesLocallyAutomated * @param servicesLocallyAutomated
* @param parentService * @param parentService
* @param tobeCreatedInitialCharValues
* @return * @return
*/ */
private Service addServicesToVariables(ServiceSpecification specrel, private Service addServicesToVariables(ServiceSpecification specrel,
ServiceOrder sor, ServiceOrderItem soi, ServiceOrder sor, ServiceOrderItem soi,
Service parentService) { Service parentService, Map<String, Map<String, String>> tobeCreatedInitialCharValues) {
logger.debug("\tService spec name :" + specrel.getName()); logger.debug("\tService spec name :" + specrel.getName());
logger.debug("\tService spec type :" + specrel.getType()); logger.debug("\tService spec type :" + specrel.getType());
...@@ -159,23 +169,23 @@ public class CreateReservedService implements JavaDelegate { ...@@ -159,23 +169,23 @@ public class CreateReservedService implements JavaDelegate {
if ( partnerOrg != null ) { if ( partnerOrg != null ) {
createdServ = createServiceByServiceSpec(sor, soi, specrel, EServiceStartMode.AUTOMATICALLY_MANAGED, partnerOrg, parentService); createdServ = createServiceByServiceSpec(sor, soi, specrel, EServiceStartMode.AUTOMATICALLY_MANAGED, partnerOrg, parentService, tobeCreatedInitialCharValues);
} }
else if (specrel.getType().equals("ResourceFacingServiceSpecification")) { else if (specrel.getType().equals("ResourceFacingServiceSpecification")) {
createdServ = createServiceByServiceSpec(sor, soi, specrel, EServiceStartMode.AUTOMATICALLY_MANAGED, null, parentService); createdServ = createServiceByServiceSpec(sor, soi, specrel, EServiceStartMode.AUTOMATICALLY_MANAGED, null, parentService, tobeCreatedInitialCharValues);
} else if ( specrel.getType().equals("CustomerFacingServiceSpecification") && (specrel.isIsBundle()!=null) && specrel.isIsBundle() ) { } else if ( specrel.getType().equals("CustomerFacingServiceSpecification") && (specrel.isIsBundle()!=null) && specrel.isIsBundle() ) {
createdServ = createServiceByServiceSpec(sor, soi, specrel, EServiceStartMode.AUTOMATICALLY_MANAGED, null, parentService); createdServ = createServiceByServiceSpec(sor, soi, specrel, EServiceStartMode.AUTOMATICALLY_MANAGED, null, parentService, tobeCreatedInitialCharValues);
} else if ( specrel.getType().equals("CustomerFacingServiceSpecification") && (specrel.findSpecCharacteristicByName("OSAUTOMATED") != null ) ) { } else if ( specrel.getType().equals("CustomerFacingServiceSpecification") && (specrel.findSpecCharacteristicByName("OSAUTOMATED") != null ) ) {
createdServ = createServiceByServiceSpec(sor, soi, specrel, EServiceStartMode.AUTOMATICALLY_MANAGED, null, parentService); createdServ = createServiceByServiceSpec(sor, soi, specrel, EServiceStartMode.AUTOMATICALLY_MANAGED, null, parentService, tobeCreatedInitialCharValues);
} else if ( specrel.getType().equals("CustomerFacingServiceSpecification") && (specrel.findSpecCharacteristicByName("testSpecRef") != null ) ) { } else if ( specrel.getType().equals("CustomerFacingServiceSpecification") && (specrel.findSpecCharacteristicByName("testSpecRef") != null ) ) {
createdServ = createServiceByServiceSpec(sor, soi, specrel, EServiceStartMode.AUTOMATICALLY_MANAGED, null, parentService); createdServ = createServiceByServiceSpec(sor, soi, specrel, EServiceStartMode.AUTOMATICALLY_MANAGED, null, parentService, tobeCreatedInitialCharValues);
} }
else { else {
createdServ = createServiceByServiceSpec(sor, soi, specrel, EServiceStartMode.MANUALLY_BY_SERVICE_PROVIDER, null, parentService); createdServ = createServiceByServiceSpec(sor, soi, specrel, EServiceStartMode.MANUALLY_BY_SERVICE_PROVIDER, null, parentService, tobeCreatedInitialCharValues);
} }
//add now the serviceRef //add now the serviceRef
...@@ -226,16 +236,20 @@ public class CreateReservedService implements JavaDelegate { ...@@ -226,16 +236,20 @@ public class CreateReservedService implements JavaDelegate {
} }
/** /**
* @param sor * @param sor
* @param soi * @param soi
* @param spec * @param spec
* @return * @param startMode
* @param partnerOrg
* @param parentService
* @param tobeCreatedInitialCharValues
* @return
*/ */
private Service createServiceByServiceSpec(ServiceOrder sor, ServiceOrderItem soi, private Service createServiceByServiceSpec(ServiceOrder sor, ServiceOrderItem soi,
ServiceSpecification spec, EServiceStartMode startMode, ServiceSpecification spec, EServiceStartMode startMode,
RelatedParty partnerOrg, Service parentService) { RelatedParty partnerOrg, Service parentService, Map<String, Map<String, String>> tobeCreatedInitialCharValues) {
ServiceCreate serviceToCreate = new ServiceCreate(); ServiceCreate serviceToCreate = new ServiceCreate();
String servicename = spec.getName(); String servicename = spec.getName();
...@@ -282,15 +296,33 @@ public class CreateReservedService implements JavaDelegate { ...@@ -282,15 +296,33 @@ public class CreateReservedService implements JavaDelegate {
} }
} }
//this map contains as key the id of the serviceSpecs to be created
//and as value a Map of initial characteristics and their values
Map<String, String> initCharValues = tobeCreatedInitialCharValues.get( spec.getId() );
//we need to be careful here with the bundle and the related Service Specs, to properly propagate the rules inside //we need to be careful here with the bundle and the related Service Specs, to properly propagate the rules inside
//first copy into the newly created service any characteristic values from the order //first copy into the newly created service any characteristic values from the order
for (ServiceSpecCharacteristic c : spec.getServiceSpecCharacteristic()) { for (ServiceSpecCharacteristic c : spec.getServiceSpecCharacteristic()) {
boolean characteristicFound = false; boolean characteristicFound = false;
//pass any initial value. This has high priority
if ( initCharValues != null ) {
if ( initCharValues.get( c.getName() ) != null ) {
Characteristic orderCharacteristic = new Characteristic()
.value( new Any( initCharValues.get( c.getName() ), initCharValues.get( c.getName() ))) ;
serviceToCreate.addServiceCharacteristicItem( helperCreateCharacteristicItem(c, orderCharacteristic ) );
characteristicFound = true;
break;
}
}
for (Characteristic orderCharacteristic : soi.getService().getServiceCharacteristic()) { for (Characteristic orderCharacteristic : soi.getService().getServiceCharacteristic()) {
String specCharacteristicToSearch = spec.getName() + "::" +c.getName(); String specCharacteristicToSearch = spec.getName() + "::" +c.getName();
if ( orderCharacteristic.getName().equals( specCharacteristicToSearch )) { //copy only characteristics that are related from the order if ( orderCharacteristic.getName().equals( specCharacteristicToSearch )) { //copy only characteristics that are related from the order
serviceToCreate.addServiceCharacteristicItem( addServiceCharacteristicItem(c, orderCharacteristic) ); serviceToCreate.addServiceCharacteristicItem( helperCreateCharacteristicItem(c, orderCharacteristic) );
characteristicFound = true; characteristicFound = true;
break; break;
} }
...@@ -301,7 +333,7 @@ public class CreateReservedService implements JavaDelegate { ...@@ -301,7 +333,7 @@ public class CreateReservedService implements JavaDelegate {
String specCharacteristicToSearch = c.getName(); String specCharacteristicToSearch = c.getName();
if ( orderCharacteristic.getName().equals( specCharacteristicToSearch )) { //copy only characteristics that are related from the order if ( orderCharacteristic.getName().equals( specCharacteristicToSearch )) { //copy only characteristics that are related from the order
serviceToCreate.addServiceCharacteristicItem( addServiceCharacteristicItem(c, orderCharacteristic) ); serviceToCreate.addServiceCharacteristicItem( helperCreateCharacteristicItem(c, orderCharacteristic) );
characteristicFound = true; characteristicFound = true;
break; break;
} }
...@@ -309,6 +341,8 @@ public class CreateReservedService implements JavaDelegate { ...@@ -309,6 +341,8 @@ public class CreateReservedService implements JavaDelegate {
} }
} }
if ( serviceToCreate.getServiceCharacteristic() == null ) { if ( serviceToCreate.getServiceCharacteristic() == null ) {
...@@ -383,7 +417,7 @@ public class CreateReservedService implements JavaDelegate { ...@@ -383,7 +417,7 @@ public class CreateReservedService implements JavaDelegate {
return null; return null;
} }
private Characteristic addServiceCharacteristicItem(ServiceSpecCharacteristic c, Characteristic orderCharacteristic) { private Characteristic helperCreateCharacteristicItem(ServiceSpecCharacteristic c, Characteristic orderCharacteristic) {
Characteristic serviceCharacteristicItem = new Characteristic(); Characteristic serviceCharacteristicItem = new Characteristic();
serviceCharacteristicItem.setName( c.getName() ); serviceCharacteristicItem.setName( c.getName() );
serviceCharacteristicItem.setValueType( c.getValueType() ); serviceCharacteristicItem.setValueType( c.getValueType() );
......
...@@ -48,6 +48,9 @@ public class ProcessCreateServiceRules implements JavaDelegate { ...@@ -48,6 +48,9 @@ public class ProcessCreateServiceRules implements JavaDelegate {
execution.setVariable("allSupportingServicesCreated", allSupportingServicesCreated ); //by default execution.setVariable("allSupportingServicesCreated", allSupportingServicesCreated ); //by default
Service contextService = null; Service contextService = null;
String contextServiceId = (String) execution.getVariable("contextServiceId"); String contextServiceId = (String) execution.getVariable("contextServiceId");
if ( contextServiceId != null ) { if ( contextServiceId != null ) {
...@@ -69,29 +72,18 @@ public class ProcessCreateServiceRules implements JavaDelegate { ...@@ -69,29 +72,18 @@ public class ProcessCreateServiceRules implements JavaDelegate {
* first find all referenced ServiceSpecs of a ServiceSpec to be created * first find all referenced ServiceSpecs of a ServiceSpec to be created
*/ */
boolean foundCreatedButNOTACTIVEServices = false; boolean foundCreatedButNOTACTIVEServices = false;
Map<String, Boolean> tobeCreated = new HashMap<>();
//this map contains as key the id of the serviceSpecs to be created
//and as value a Map of initial characteristics and their values
Map<String, Map<String,String>> tobeCreated = new HashMap<>();
for (ServiceSpecRelationship specRels : spec.getServiceSpecRelationship()) { for (ServiceSpecRelationship specRels : spec.getServiceSpecRelationship()) {
logger.debug("\tService specRelsId:" + specRels.getId()); logger.debug("\tService specRelsId:" + specRels.getId());
tobeCreated.put(specRels.getId(), true); tobeCreated.put(specRels.getId(), null);
} }
for ( ServiceRef serviceRef: contextService.getSupportingService() ) {
Service theServiceReferenced = serviceOrderManager.retrieveService( serviceRef.getId() );
if ( tobeCreated.get(theServiceReferenced.getServiceSpecificationRef().getId() ) != null ) {
tobeCreated.put( theServiceReferenced.getServiceSpecificationRef().getId(), false);
}
if ( theServiceReferenced != null ) {
if ( theServiceReferenced.getState().equals( ServiceStateType.RESERVED) ) {
foundCreatedButNOTACTIVEServices = true;
}
}
}
/** /**
...@@ -123,20 +115,45 @@ public class ProcessCreateServiceRules implements JavaDelegate { ...@@ -123,20 +115,45 @@ public class ProcessCreateServiceRules implements JavaDelegate {
for (String serviceId : vars.getOutParams().keySet()) { for (String serviceId : vars.getOutParams().keySet()) {
if ( vars.getOutParams().get(serviceId) !=null) { if ( vars.getOutParams().get(serviceId) !=null) {
if ( vars.getOutParams().get(serviceId).equals( "true") ) {
tobeCreated.put( serviceId, true && tobeCreated.get(serviceId) );
} else { if ( vars.getOutParams().get(serviceId) != null && vars.getOutParams().get(serviceId).get("_CREATESERVICEREF_") !=null) {
tobeCreated.put( serviceId, false);
allSupportingServicesCreated = false; if ( vars.getOutParams().get(serviceId).get("_CREATESERVICEREF_").equals( "true") ) {
} vars.getOutParams().get(serviceId).remove( "_CREATESERVICEREF_" );
HashMap<String, String> myChars = new HashMap< String , String >( vars.getOutParams().get(serviceId) );
tobeCreated.put( serviceId, myChars );
} else {
tobeCreated.remove( serviceId);
allSupportingServicesCreated = false;
}
}
} }
} }
//now compare those to be created, with those already created
for ( ServiceRef serviceRef: contextService.getSupportingService() ) {
Service theServiceReferenced = serviceOrderManager.retrieveService( serviceRef.getId() );
if ( tobeCreated.containsKey(theServiceReferenced.getServiceSpecificationRef().getId() ) ) {
tobeCreated.remove( theServiceReferenced.getServiceSpecificationRef().getId());
}
if ( theServiceReferenced != null ) {
if ( theServiceReferenced.getState().equals( ServiceStateType.RESERVED) ) {
foundCreatedButNOTACTIVEServices = true;
}
}
}
serviceOrderManager.updateService( contextService.getId() , supd, false); //update context service serviceOrderManager.updateService( contextService.getId() , supd, false); //update context service
List<String> servicesToCreate = new ArrayList<>(); List<String> servicesToCreate = new ArrayList<>();
for (String specid : tobeCreated.keySet()) { for (String specid : tobeCreated.keySet()) {
if ( tobeCreated.get(specid) ) { if ( tobeCreated.get(specid) !=null ) {
servicesToCreate.add(specid); servicesToCreate.add(specid);
allSupportingServicesCreated = false; allSupportingServicesCreated = false;
} }
...@@ -161,11 +178,21 @@ public class ProcessCreateServiceRules implements JavaDelegate { ...@@ -161,11 +178,21 @@ public class ProcessCreateServiceRules implements JavaDelegate {
} }
if ( contextService.getState().equals( ServiceStateType.INACTIVE ) || contextService.getState().equals( ServiceStateType.TERMINATED ) ) {
allSupportingServicesCreatedAndActive = true;
allSupportingServicesCreated = true;
// this will help us to avoid a deadlock if a failure occurs
}
execution.setVariable("allSupportingServicesCreated", allSupportingServicesCreated ); execution.setVariable("allSupportingServicesCreated", allSupportingServicesCreated );
execution.setVariable("allSupportingServicesCreatedAndActive", allSupportingServicesCreatedAndActive && allSupportingServicesCreated ); //by default execution.setVariable("allSupportingServicesCreatedAndActive", allSupportingServicesCreatedAndActive && allSupportingServicesCreated ); //by default
execution.setVariable("parentServiceId", contextServiceId); execution.setVariable("parentServiceId", contextServiceId);
execution.setVariable("serviceSpecsToCreate", servicesToCreate); execution.setVariable("serviceSpecsToCreate", servicesToCreate);
execution.setVariable("serviceSpecsToCreateInitialCharValues", tobeCreated);
} }
......
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