diff --git a/src/main/java/org/etsi/osl/tmf/sim638/service/ServiceRepoService.java b/src/main/java/org/etsi/osl/tmf/sim638/service/ServiceRepoService.java index d6ac3af26b7fd7ada59ba3f9584ece6ac547245f..9e7bb038f73479632e8f636bb600bbf8ab7cd946 100644 --- a/src/main/java/org/etsi/osl/tmf/sim638/service/ServiceRepoService.java +++ b/src/main/java/org/etsi/osl/tmf/sim638/service/ServiceRepoService.java @@ -286,6 +286,7 @@ public class ServiceRepoService { } + @Transactional public Service addService(@Valid ServiceCreate service) { logger.info("Will add service: " + service.getName() ); Service s = new Service(); @@ -335,11 +336,12 @@ public class ServiceRepoService { Note noteItem = new Note(); noteItem.setText("Service " + s.getState() ); - noteItem.setAuthor("API"); + noteItem.setAuthor("SIM-638"); noteItem.setDate(OffsetDateTime.now(ZoneOffset.UTC) ); s.addNoteItem(noteItem); - s = this.serviceRepo.save( s ); + + s = this.serviceRepo.save( s ); raiseServiceCreateNotification(s); return s; @@ -353,22 +355,7 @@ public class ServiceRepoService { .orElse(null); } - /** - * @param id - * @param servUpd - * @param triggerServiceActionQueue - * @param updatedFromParentService - * @param updatedFromChildService - * @return - */ - /** - * @param id - * @param servUpd - * @param triggerServiceActionQueue - * @param updatedFromParentService - * @param updatedFromChildService - * @return - */ + /** * @param id * @param servUpd @@ -379,6 +366,9 @@ public class ServiceRepoService { */ @Transactional public Service updateService(String id, @Valid ServiceUpdate servUpd, boolean triggerServiceActionQueue, Service updatedFromParentService, Service updatedFromChildService ) { + + + logger.debug("================> Will updateService = " + id ); //Service service = this.findByUuid(id); Service service = this.getServiceEager(id); @@ -387,7 +377,10 @@ public class ServiceRepoService { logger.error("Service cannot be found in registry, UUID: " + id ); return null; } + + + logger.info("Will update service: " + service.getName() ); //logger.info("Will update service details: " + s.toString() ); @@ -400,7 +393,8 @@ public class ServiceRepoService { e.printStackTrace(); } - + + if (servUpd.getType()!=null) { service.setType(servUpd.getType()); } @@ -541,6 +535,8 @@ public class ServiceRepoService { } else { service.addServiceCharacteristicItem(n); + + if ( !n.getName().contains("::") ) { //it is not a child characteristic serviceCharacteristicChanged = true; charChangedForNotes += n.getName() + ", "; @@ -585,9 +581,10 @@ public class ServiceRepoService { if (stateChanged) { Note noteItem = new Note(); noteItem.setText("Service is " + service.getState() ); - noteItem.setAuthor("API"); + noteItem.setAuthor("SIM-638"); noteItem.setDate(OffsetDateTime.now(ZoneOffset.UTC) ); service.addNoteItem(noteItem); + logger.debug("=============SERVICE STATE ================================> " + service.getState() ); } @@ -633,11 +630,11 @@ public class ServiceRepoService { } } - - + service = this.serviceRepo.save( service ); + String requestedServiceAsJson = null; try { requestedServiceAsJson = mapper.writeValueAsString( service ); @@ -650,40 +647,28 @@ public class ServiceRepoService { * Save in ServiceActionQueueItem */ - if (triggerServiceActionQueue && stateChanged) { - ServiceActionQueueItem saqi = new ServiceActionQueueItem(); - saqi.setServiceRefId( id ); - saqi.setOriginalServiceInJSON( originaServiceAsJson ); - if (stateChanged) { - if ( service.getState().equals( ServiceStateType.INACTIVE) ) { - saqi.setAction( ServiceActionQueueAction.DEACTIVATE ); - }else if ( service.getState().equals( ServiceStateType.TERMINATED) ) { - saqi.setAction( ServiceActionQueueAction.TERMINATE ); - } - - } - - if ( saqi.getAction() != ServiceActionQueueAction.NONE ) { - this.addServiceActionQueueItem(service, saqi); - } - } - - -// //here on any state change of a Service we must send an ActionQueueItem that reflects the state changed with the Action - if ( stateChanged ) { - ServiceActionQueueItem saqi = new ServiceActionQueueItem(); - saqi.setServiceRefId( id ); - saqi.setOriginalServiceInJSON( originaServiceAsJson ); - if ( service.getState().equals( ServiceStateType.ACTIVE) ) { - saqi.setAction( ServiceActionQueueAction.EVALUATE_STATE_CHANGE_TOACTIVE ); - this.addServiceActionQueueItem(service, saqi); - }else if ( previousState!=null && previousState.equals( ServiceStateType.ACTIVE) ) { - saqi.setAction( ServiceActionQueueAction.EVALUATE_STATE_CHANGE_TOINACTIVE ); - this.addServiceActionQueueItem(service, saqi); - } - } - - if ( serviceCharacteristicChanged && service.getState().equals( ServiceStateType.ACTIVE) && previousState!=null && previousState.equals( ServiceStateType.ACTIVE) && triggerServiceActionQueue ) { + Boolean childServiceCharacteristicChanged = false; + + if ( stateChanged ) { + ServiceActionQueueItem saqi = new ServiceActionQueueItem(); + saqi.setServiceRefId( id ); + saqi.setOriginalServiceInJSON( originaServiceAsJson ); + + if ( service.getState().equals( ServiceStateType.INACTIVE) ) { + saqi.setAction( ServiceActionQueueAction.DEACTIVATE ); + }else if ( service.getState().equals( ServiceStateType.TERMINATED) ) { + saqi.setAction( ServiceActionQueueAction.TERMINATE ); + }else if ( service.getState().equals( ServiceStateType.ACTIVE) ) { + saqi.setAction( ServiceActionQueueAction.EVALUATE_STATE_CHANGE_TOACTIVE ); + }else if ( previousState!=null && previousState.equals( ServiceStateType.ACTIVE) ) { + saqi.setAction( ServiceActionQueueAction.EVALUATE_STATE_CHANGE_TOINACTIVE ); + } + + if ( saqi.getAction() != ServiceActionQueueAction.NONE ) { + logger.debug("==========addServiceActionQueueItem==============> saqi.getAction() = " + saqi.getAction() ); + this.addServiceActionQueueItem(service, saqi); + } + } else if ( serviceCharacteristicChanged && service.getState().equals( ServiceStateType.ACTIVE) && previousState!=null && previousState.equals( ServiceStateType.ACTIVE) && triggerServiceActionQueue ) { ServiceActionQueueItem saqi = new ServiceActionQueueItem(); saqi.setServiceRefId( id ); saqi.setOriginalServiceInJSON( originaServiceAsJson ); @@ -691,7 +676,9 @@ public class ServiceRepoService { if ( serviceCharacteristicChangedContainsPrimitive ) { saqi.setAction( ServiceActionQueueAction.EVALUATE_CHARACTERISTIC_CHANGED_MANODAY2 ); } + logger.debug("==========addServiceActionQueueItem==============> serviceCharacteristicChanged && service.getState().eq charChangedForNotes= " + charChangedForNotes); this.addServiceActionQueueItem(service, saqi); + childServiceCharacteristicChanged = true; } @@ -703,26 +690,10 @@ public class ServiceRepoService { * Update any parent service */ for (ServiceRelationship serviceRelationship : service.getServiceRelationship()) { - if (serviceRelationship.getRelationshipType().equals("ChildService")) { + if (serviceRelationship.getRelationshipType().equals("ChildService") ) { if (serviceRelationship.getService() != null) { - - - if (serviceCharacteristicChanged) { - if (updatedFromParentService == null || (updatedFromParentService != null && !updatedFromParentService.getId().equals(serviceRelationship.getService().getId()))) { // avoid circular - ServiceActionQueueItem saqi = new ServiceActionQueueItem(); // this will trigger lcm rule to parent - saqi.setServiceRefId(serviceRelationship.getService().getId()); - try { - saqi.setOriginalServiceInJSON( mapper.writeValueAsString( service ) ); //pass the child service as is - } catch (JsonProcessingException e) { - e.printStackTrace(); - } - saqi.setAction(ServiceActionQueueAction.EVALUATE_CHILD_CHARACTERISTIC_CHANGED); - this.addServiceActionQueueItem(service, saqi); - } - - } - if (stateChanged) { + if (stateChanged || childServiceCharacteristicChanged) { if (updatedFromParentService == null || (updatedFromParentService != null && !updatedFromParentService.getId().equals(serviceRelationship.getService().getId()))) { // avoid circular ServiceActionQueueItem saqi = new ServiceActionQueueItem(); // this will trigger lcm rule to parent saqi.setServiceRefId(serviceRelationship.getService().getId()); @@ -731,13 +702,16 @@ public class ServiceRepoService { } catch (JsonProcessingException e) { e.printStackTrace(); } - saqi.setAction(ServiceActionQueueAction.EVALUATE_CHILD_STATE_CHANGE ); + if (stateChanged) { + saqi.setAction(ServiceActionQueueAction.EVALUATE_CHILD_STATE_CHANGE ); + logger.debug("==========addServiceActionQueueItem==============> EVALUATE_CHILD_STATE_CHANGE " + charChangedForNotes); + } else if ( childServiceCharacteristicChanged) { + saqi.setAction(ServiceActionQueueAction.EVALUATE_CHILD_CHARACTERISTIC_CHANGED); + logger.debug("==========addServiceActionQueueItem==============> EVALUATE_CHILD_CHARACTERISTIC_CHANGED " + charChangedForNotes); + } this.addServiceActionQueueItem(service, saqi); } } - - - } } } @@ -804,8 +778,7 @@ public class ServiceRepoService { // } catch (FileNotFoundException e) { // // TODO Auto-generated catch block // e.printStackTrace(); -// } - logger.info("======================================================================================================"); +// } } return service; @@ -921,10 +894,10 @@ public class ServiceRepoService { if ( schart!= null ) { String teest = schart.getValue().getValue(); - logger.info("schart size = " + teest.length() ); + logger.debug("schart size = " + teest.length() ); - logger.info("schart " + teest ); - logger.info("======================================================================================================"); + logger.debug("schart " + teest ); + logger.debug("======================================================================================================"); } return res; @@ -1011,6 +984,9 @@ public class ServiceRepoService { //find any similar action inqueue and delete them, so to keep this one as the most recent List result = this.serviceActionQueueRepo.findByServiceRefIdAndAction(item.getServiceRefId(), item.getAction()); logger.debug("Will add ServiceActionQueueItem ServiceRefId result: " +result.size() ); + if (result.size()>0) { //essentially it will not delete any requests, but just return with not adding the new action since it is already exists + return item; + } this.serviceActionQueueRepo.deleteByServiceRefIdAndAction(item.getServiceRefId(), item.getAction()); } diff --git a/src/test/java/org/etsi/osl/services/api/ServiceInventoryIntegrationTest.java b/src/test/java/org/etsi/osl/services/api/ServiceInventoryIntegrationTest.java index 93e25542960cf7b22af6b7b4fd3188dfcffa60b9..68579fa33d1b21cc8afce6516bf1f92d7816d5e4 100644 --- a/src/test/java/org/etsi/osl/services/api/ServiceInventoryIntegrationTest.java +++ b/src/test/java/org/etsi/osl/services/api/ServiceInventoryIntegrationTest.java @@ -327,7 +327,7 @@ public class ServiceInventoryIntegrationTest { assertThat( responseSOUpd.getServiceCharacteristicByName( "DeploymentRequestID" ).getValue().getValue() ).isEqualTo( "1007" ) ; - assertThat( serviceRepoService.findAllServiceActionQueueItems().size() ).isEqualTo( 3 ); + assertThat( serviceRepoService.findAllServiceActionQueueItems().size() ).isEqualTo( 2 ); assertThat( serviceRepoService.findAllServiceActionQueueItems().get(0).getAction() ).isEqualTo(ServiceActionQueueAction.EVALUATE_STATE_CHANGE_TOACTIVE ); } diff --git a/src/test/java/org/etsi/osl/services/api/ServiceOrderIntegrationTest.java b/src/test/java/org/etsi/osl/services/api/ServiceOrderIntegrationTest.java index b05c6e78ece77399cddcc319f4ea64a7d57b7bd6..daeb2ed9bf66b719b944bc05b6f1d556aed9845b 100644 --- a/src/test/java/org/etsi/osl/services/api/ServiceOrderIntegrationTest.java +++ b/src/test/java/org/etsi/osl/services/api/ServiceOrderIntegrationTest.java @@ -310,6 +310,7 @@ public class ServiceOrderIntegrationTest { serviceOrderref.setId(responseSO.getId()); serviceOrderref.setServiceOrderItemId((new ArrayList<>(responseSO.getOrderItem())).get(0).getId()); s.addServiceOrderItem(serviceOrderref); + s.setServiceCharacteristic( new ArrayList<>()); Service createdServ = serviceRepoService.addService(s); diff --git a/src/test/java/org/etsi/osl/services/api/sim638/ServiceRepoServiceTest.java b/src/test/java/org/etsi/osl/services/api/sim638/ServiceRepoServiceTest.java index c647b1090370d8ba4b2319cbaf4bb140e1640407..01249450a2a853e679938b4bbf9607ec7bf4147c 100644 --- a/src/test/java/org/etsi/osl/services/api/sim638/ServiceRepoServiceTest.java +++ b/src/test/java/org/etsi/osl/services/api/sim638/ServiceRepoServiceTest.java @@ -296,11 +296,20 @@ public class ServiceRepoServiceTest { assertThat( updatedService.getServiceCharacteristic().size() ).isEqualTo( 7 ); assertThat( updatedService.getSupportingResource().size() ).isEqualTo( 1); + + + assertThat( updatedService.getServiceCharacteristicByName("NSLCM").getValue().getValue() ).isEqualTo( "nslcm_test" ); ResourceUpdate resourceUpdate = new ResourceUpdate(); + + org.etsi.osl.tmf.ri639.model.Characteristic resCharacteristicItem = new org.etsi.osl.tmf.ri639.model.Characteristic(); + resCharacteristicItem.setName( "NSLCM" ); + resCharacteristicItem.setValue( new Any("nslcm_test2")); + resourceUpdate.addResourceCharacteristicItem(resCharacteristicItem); + resCharacteristicItem.setName( "newChar" ); resCharacteristicItem.setValue( new Any("myval0")); resourceUpdate.addResourceCharacteristicItem(resCharacteristicItem); @@ -458,6 +467,44 @@ public class ServiceRepoServiceTest { return response; } + @Test + public void testFindNextStateBasedOnSupportingResources() throws Exception { + Service s = new Service(); + s.setState(ServiceStateType.RESERVED); + List rlist = new ArrayList(); + Resource r1 = new Resource(); + Resource r2 = new Resource(); + r1.setResourceStatus(ResourceStatusType.RESERVED); + r2.setResourceStatus(ResourceStatusType.RESERVED); + rlist.add(r1); + rlist.add(r2); + ServiceStateType nstate = s.findNextStateBasedOnResourceList(rlist); + assertThat(nstate).isEqualTo( ServiceStateType.RESERVED ); + + r1.setResourceStatus(ResourceStatusType.AVAILABLE); + nstate = s.findNextStateBasedOnResourceList(rlist); + assertThat(nstate).isEqualTo( ServiceStateType.RESERVED ); + + r2.setResourceStatus(ResourceStatusType.AVAILABLE); + nstate = s.findNextStateBasedOnResourceList(rlist); + assertThat(nstate).isEqualTo( ServiceStateType.ACTIVE ); + + s.setState( ServiceStateType.ACTIVE ); + r1.setResourceStatus(ResourceStatusType.UNKNOWN); + nstate = s.findNextStateBasedOnResourceList(rlist); + assertThat(nstate).isEqualTo( ServiceStateType.ACTIVE ); + + r1.setResourceStatus(ResourceStatusType.SUSPENDED); + nstate = s.findNextStateBasedOnResourceList(rlist); + assertThat(nstate).isEqualTo( ServiceStateType.TERMINATED ); + + s.setState( ServiceStateType.TERMINATED ); + r1.setResourceStatus(ResourceStatusType.AVAILABLE); + nstate = s.findNextStateBasedOnResourceList(rlist); + assertThat(nstate).isEqualTo( ServiceStateType.TERMINATED ); + + + } private ServiceSpecification createServiceSpec(String sspectext, ServiceSpecificationCreate sspeccr1) throws Exception{ String response = mvc.perform(MockMvcRequestBuilders.post("/serviceCatalogManagement/v4/serviceSpecification")