From 7660bce2315e6208a53472807afdeb648f672bcb Mon Sep 17 00:00:00 2001 From: Christos Tranoris Date: Tue, 5 Dec 2023 18:52:39 +0200 Subject: [PATCH] closes #7 --- .../reposervices/ResourceRepoService.java | 2 +- .../sim638/api/ServiceApiRouteBuilder.java | 19 ++++- .../sim638/service/ServiceRepoService.java | 72 ++++++++++++++++++- 3 files changed, 89 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/etsi/osl/tmf/ri639/reposervices/ResourceRepoService.java b/src/main/java/org/etsi/osl/tmf/ri639/reposervices/ResourceRepoService.java index 08800a8..15a45d9 100644 --- a/src/main/java/org/etsi/osl/tmf/ri639/reposervices/ResourceRepoService.java +++ b/src/main/java/org/etsi/osl/tmf/ri639/reposervices/ResourceRepoService.java @@ -341,7 +341,7 @@ public class ResourceRepoService { boolean resourceStateChanged = false; if (resourceUpd.getResourceStatus() != null) { - if (resourceUpd.getResourceStatus().equals(resource.getResourceStatus())) { + if (!resourceUpd.getResourceStatus().equals(resource.getResourceStatus())) { resourceStateChanged = true; } resource.setResourceStatus(resourceUpd.getResourceStatus()); diff --git a/src/main/java/org/etsi/osl/tmf/sim638/api/ServiceApiRouteBuilder.java b/src/main/java/org/etsi/osl/tmf/sim638/api/ServiceApiRouteBuilder.java index b9e7e4a..c3ca3c8 100644 --- a/src/main/java/org/etsi/osl/tmf/sim638/api/ServiceApiRouteBuilder.java +++ b/src/main/java/org/etsi/osl/tmf/sim638/api/ServiceApiRouteBuilder.java @@ -32,6 +32,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.etsi.osl.tmf.common.model.Notification; import org.etsi.osl.tmf.ri639.model.ResourceAttributeValueChangeNotification; +import org.etsi.osl.tmf.ri639.model.ResourceCreateNotification; import org.etsi.osl.tmf.ri639.model.ResourceStateChangeNotification; import org.etsi.osl.tmf.sim638.model.ServiceActionQueueItem; import org.etsi.osl.tmf.sim638.model.ServiceCreate; @@ -93,11 +94,13 @@ public class ServiceApiRouteBuilder extends RouteBuilder { @Value("${EVENT_RESOURCE_ATTRIBUTE_VALUE_CHANGED}") private String EVENT_RESOURCE_ATTRIBUTE_VALUE_CHANGED = ""; - - //services care to take this event in case they are related to a specific resource (see CRs) @Value("${EVENT_RESOURCE_STATE_CHANGED}") private String EVENT_RESOURCE_STATE_CHANGED = ""; + + + @Value("${EVENT_RESOURCE_CREATE}") + private String EVENT_RESOURCE_CREATE = ""; @Autowired private ProducerTemplate template; @@ -185,6 +188,8 @@ public class ServiceApiRouteBuilder extends RouteBuilder { .unmarshal().json( JsonLibrary.Jackson, DeploymentDescriptor.class, true) .bean( serviceRepoService, "nfvCatalogNSResourceChanged(${body})"); + + from( EVENT_RESOURCE_STATE_CHANGED ) .log(LoggingLevel.INFO, log, EVENT_RESOURCE_STATE_CHANGED + " message received and will be processed for service inventory!") @@ -192,6 +197,16 @@ public class ServiceApiRouteBuilder extends RouteBuilder { .unmarshal().json( JsonLibrary.Jackson, ResourceStateChangeNotification.class, true) .bean( serviceRepoService, "resourceStateChangedEvent(${body})"); + + from( EVENT_RESOURCE_CREATE ) + .log(LoggingLevel.INFO, log, EVENT_RESOURCE_CREATE + " message received and will be processed for service inventory!") + .to("log:DEBUG?showBody=true&showHeaders=true") + .unmarshal().json( JsonLibrary.Jackson, ResourceCreateNotification.class, true) + .bean( serviceRepoService, "resourceCreatedEvent(${body})"); + + + + from( EVENT_RESOURCE_ATTRIBUTE_VALUE_CHANGED ) .log(LoggingLevel.INFO, log, EVENT_RESOURCE_ATTRIBUTE_VALUE_CHANGED + " message received and will be processed for service inventory!") .to("log:DEBUG?showBody=true&showHeaders=true") 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 df8c2bd..261fbab 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 @@ -44,6 +44,7 @@ import org.etsi.osl.tmf.common.model.service.ServiceStateType; import org.etsi.osl.tmf.prm669.model.RelatedParty; import org.etsi.osl.tmf.ri639.model.Resource; import org.etsi.osl.tmf.ri639.model.ResourceAttributeValueChangeNotification; +import org.etsi.osl.tmf.ri639.model.ResourceCreateNotification; import org.etsi.osl.tmf.ri639.model.ResourceStateChangeNotification; import org.etsi.osl.tmf.scm633.reposervices.ServiceSpecificationRepoService; import org.etsi.osl.tmf.sim638.api.ServiceApiRouteBuilderEvents; @@ -530,6 +531,12 @@ public class ServiceRepoService { service.addNoteItem(noteItem); } + + + if (charChangedForNotes.contains( "reconciledAt") ) { //this is just a sync message, so we need to igore such changes + serviceCharacteristicChanged = false; + } + if (serviceCharacteristicChanged) { Note noteItem = new Note(); noteItem.setText("Service Characteristic changed: " + charChangedForNotes ); @@ -987,13 +994,76 @@ public class ServiceRepoService { this.updateService( aService.getId(), supd , true, null, null); //update the service //} } + + } + + + @Transactional + public void resourceCreatedEvent(@Valid ResourceCreateNotification resNotif) { + + logger.debug("resourceCreatedEvent"); + Resource res = resNotif.getEvent().getEvent().getResource(); + logger.info("Will update services related to this resource with id = " + res.getId() ); + + var aservices = findServicesHavingThisSupportingResourceID( res.getId() ); + + for (Service as : aservices) { + ServiceUpdate supd = new ServiceUpdate(); + + Service aService = findByUuid(as.getId()); + + //if ( aService.getState().equals( ServiceStateType.ACTIVE ) ) { + if ( res.getResourceStatus() != null ) { + switch (res.getResourceStatus()) { + case STANDBY: { + supd.setState( ServiceStateType.RESERVED); + break; + } + case SUSPENDED: { + supd.setState( ServiceStateType.INACTIVE); + break; + } + case RESERVED: { + supd.setState( ServiceStateType.RESERVED); + break; + } + case UNKNOWN: { + if (aService.getState().equals( ServiceStateType.ACTIVE )) { + supd.setState( ServiceStateType.TERMINATED); + } + break; + } + case ALARM: { + supd.setState( ServiceStateType.INACTIVE); + break; + } + default: + break; + } + } + + + Note n = new Note(); + n.setText("Supporting Resource "+ res.getId() + " State Changed with status: " + res.getResourceStatus()); + n.setAuthor( "SIM638-API" ); + n.setDate( OffsetDateTime.now(ZoneOffset.UTC).toString() ); + supd.addNoteItem( n ); + + this.updateService( aService.getId(), supd , true, null, null); //update the service + //} //if ( aService.getState().equals( ServiceStateType.ACTIVE ) ) { + } + + + updateResourceFromKubernetesLabel( res ); + + } @Transactional public void resourceStateChangedEvent(@Valid ResourceStateChangeNotification resNotif) { - logger.debug("ResourceAttributeValueChangeNotification"); + logger.debug("resourceStateChangedEvent"); Resource res = resNotif.getEvent().getEvent().getResource(); logger.info("Will update services related to this resource with id = " + res.getId() ); -- GitLab