Loading src/main/java/org/etsi/osl/tmf/ram702/api/ResourceActivationApiRouteBuilder.java +14 −14 Original line number Original line Diff line number Diff line Loading @@ -46,17 +46,17 @@ public class ResourceActivationApiRouteBuilder extends RouteBuilder { private static final transient Log logger = LogFactory.getLog(ResourceActivationApiRouteBuilder.class.getName()); private static final transient Log logger = LogFactory.getLog(ResourceActivationApiRouteBuilder.class.getName()); @Value("${CATALOG_ADD_RESOURCE}") @Value("${CATALOG_ADD_RESOURCEACTIVATION}") private String CATALOG_ADD_RESOURCE = ""; private String CATALOG_ADD_RESOURCEACTIVATION = ""; @Value("${CATALOG_UPD_RESOURCE}") @Value("${CATALOG_UPD_RESOURCEACTIVATION}") private String CATALOG_UPD_RESOURCE = ""; private String CATALOG_UPD_RESOURCEACTIVATION = ""; @Value("${CATALOG_UPDADD_RESOURCE}") @Value("${CATALOG_UPDADD_RESOURCEACTIVATION}") private String CATALOG_UPDADD_RESOURCE = ""; private String CATALOG_UPDADD_RESOURCEACTIVATION = ""; @Value("${CATALOG_GET_RESOURCE_BY_ID}") @Value("${CATALOG_GET_RESOURCEACTIVATION_BY_ID}") private String CATALOG_GET_RESOURCE_BY_ID = ""; private String CATALOG_GET_RESOURCEACTIVATION_BY_ID = ""; @Autowired @Autowired private ProducerTemplate template; private ProducerTemplate template; Loading @@ -67,8 +67,8 @@ public class ResourceActivationApiRouteBuilder extends RouteBuilder { @Override @Override public void configure() throws Exception { public void configure() throws Exception { from( CATALOG_ADD_RESOURCE ) from( CATALOG_ADD_RESOURCEACTIVATION ) .log(LoggingLevel.INFO, log, CATALOG_ADD_RESOURCE + " message received!") .log(LoggingLevel.INFO, log, CATALOG_ADD_RESOURCEACTIVATION + " message received!") .to("log:DEBUG?showBody=true&showHeaders=true") .to("log:DEBUG?showBody=true&showHeaders=true") .unmarshal().json( JsonLibrary.Jackson, ResourceCreate.class, true) .unmarshal().json( JsonLibrary.Jackson, ResourceCreate.class, true) .bean( resourceRepoService, "addResource(${body})") .bean( resourceRepoService, "addResource(${body})") Loading @@ -76,16 +76,16 @@ public class ResourceActivationApiRouteBuilder extends RouteBuilder { .json( JsonLibrary.Jackson) .json( JsonLibrary.Jackson) .convertBodyTo( String.class ); .convertBodyTo( String.class ); from( CATALOG_UPD_RESOURCE ) from( CATALOG_UPD_RESOURCEACTIVATION ) .log(LoggingLevel.INFO, log, CATALOG_UPD_RESOURCE + " message received!") .log(LoggingLevel.INFO, log, CATALOG_UPD_RESOURCEACTIVATION + " message received!") .to("log:DEBUG?showBody=true&showHeaders=true") .to("log:DEBUG?showBody=true&showHeaders=true") .unmarshal().json( JsonLibrary.Jackson, ResourceUpdate.class, true) .unmarshal().json( JsonLibrary.Jackson, ResourceUpdate.class, true) .bean( resourceRepoService, "updateResource(${header.resourceId}, ${body}, ${header.triggerServiceActionQueue} )") .bean( resourceRepoService, "updateResource(${header.resourceId}, ${body}, ${header.triggerServiceActionQueue} )") .marshal().json( JsonLibrary.Jackson) .marshal().json( JsonLibrary.Jackson) .convertBodyTo( String.class ); .convertBodyTo( String.class ); from( CATALOG_UPDADD_RESOURCE ) from( CATALOG_UPDADD_RESOURCEACTIVATION ) .log(LoggingLevel.INFO, log, CATALOG_UPDADD_RESOURCE + " message received!") .log(LoggingLevel.INFO, log, CATALOG_UPDADD_RESOURCEACTIVATION + " message received!") .to("log:DEBUG?showBody=true&showHeaders=true") .to("log:DEBUG?showBody=true&showHeaders=true") .unmarshal().json( JsonLibrary.Jackson, ResourceCreate.class, true) .unmarshal().json( JsonLibrary.Jackson, ResourceCreate.class, true) .bean( resourceRepoService, "addOrUpdateResourceByNameCategoryVersion(${header.aname},${header.acategory}, ${header.aversion}, ${body})") .bean( resourceRepoService, "addOrUpdateResourceByNameCategoryVersion(${header.aname},${header.acategory}, ${header.aversion}, ${body})") Loading src/main/java/org/etsi/osl/tmf/ram702/api/ResourceActivationApiRouteBuilderEvents.javadeleted 100644 → 0 +0 −112 Original line number Original line Diff line number Diff line /*- * ========================LICENSE_START================================= * org.etsi.osl.tmf.api * %% * Copyright (C) 2024 openslice.io * %% * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * =========================LICENSE_END================================== */ package org.etsi.osl.tmf.ram702.api; import java.io.IOException; import java.util.HashMap; import java.util.Map; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.databind.ObjectMapper; import org.apache.camel.ProducerTemplate; import org.apache.camel.builder.RouteBuilder; 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.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Configuration; import org.springframework.stereotype.Component; @Configuration // @RefreshScope @Component public class ResourceActivationApiRouteBuilderEvents extends RouteBuilder { private static final transient Log logger = LogFactory.getLog(ResourceActivationApiRouteBuilderEvents.class.getName()); @Value("${EVENT_RESOURCE_CREATE}") private String EVENT_RESOURCE_CREATE = ""; @Value("${EVENT_RESOURCE_STATE_CHANGED}") private String EVENT_RESOURCE_STATE_CHANGED = ""; @Value("${EVENT_RESOURCE_DELETE}") private String EVENT_RESOURCE_DELETE = ""; @Value("${EVENT_RESOURCE_ATTRIBUTE_VALUE_CHANGED}") private String EVENT_RESOURCE_ATTRIBUTE_VALUE_CHANGED = ""; @Autowired private ProducerTemplate template; @Override public void configure() throws Exception { } /** * @param n */ public void publishEvent(final Notification n, final String objId) { n.setEventType(n.getClass().getName()); logger.info("will send Event topic for type " + n.getEventType()); try { String msgtopic = ""; if (n instanceof ResourceCreateNotification) { msgtopic = EVENT_RESOURCE_CREATE; } else if (n instanceof ResourceAttributeValueChangeNotification) { msgtopic = EVENT_RESOURCE_ATTRIBUTE_VALUE_CHANGED; }else if (n instanceof ResourceStateChangeNotification ) { msgtopic = EVENT_RESOURCE_STATE_CHANGED; } Map<String, Object> map = new HashMap<>(); map.put("eventid", n.getEventId()); map.put("objId", objId); template.sendBodyAndHeaders(msgtopic, toJsonString(n), map); } catch (Exception e) { logger.error("Cannot send Event . " + e.getStackTrace()); } } static String toJsonString(Object object) throws IOException { ObjectMapper mapper = new ObjectMapper(); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); return mapper.writeValueAsString(object); } } src/main/java/org/etsi/osl/tmf/sim638/service/ServiceRepoService.java +56 −58 Original line number Original line Diff line number Diff line Loading @@ -578,11 +578,15 @@ public class ServiceRepoService { } } if (serviceCharacteristicChanged) { if (serviceCharacteristicChanged) { if (service.getServiceCharacteristicByName("_DETAILED_NOTES_") != null) { Note noteItem = new Note(); Note noteItem = new Note(); noteItem.setText("Service Characteristic changed: " + charChangedForNotes ); noteItem.setText("Service Characteristic changed: " + charChangedForNotes ); noteItem.setAuthor("API"); noteItem.setAuthor("SIM638-API"); noteItem.setDate(OffsetDateTime.now(ZoneOffset.UTC) ); noteItem.setDate(OffsetDateTime.now(ZoneOffset.UTC) ); service.addNoteItem(noteItem); service.addNoteItem(noteItem); } } } Loading Loading @@ -1114,20 +1118,37 @@ public class ServiceRepoService { public void updateServicesHavingThisSupportingResource(@Valid Resource res) { public void updateServicesHavingThisSupportingResource(@Valid Resource res) { try { try { logger.info("Will update services related to this resource with id = " + res.getId() ); logger.debug("Will update services related to this resource with id = " + res.getId() ); var aservices = findServicesHavingThisSupportingResourceID( res.getId() ); var aservices = findServicesHavingThisSupportingResourceID( res.getId() ); logger.debug("services.found = " + aservices.size() ); for (Service as : aservices) { for (Service as : aservices) { Service aService = findByUuid(as.getId()); Service aService = findByUuid(as.getId()); //if ( aService.getState().equals( ServiceStateType.ACTIVE ) ) { List<Resource> rlist = new ArrayList<Resource>(); for (ResourceRef rref : aService.getSupportingResource()) { Optional<Resource> result = resourceRepo.findByUuid(rref.getId()); if (result.isPresent()) { rlist.add( result.get() ); } } rlist.add(res); //add also this one ServiceStateType nextState = aService.findNextStateBasedOnSupportingResources(rlist); ServiceUpdate supd = new ServiceUpdate(); ServiceUpdate supd = new ServiceUpdate(); supd.setState(nextState); String stateText=""; if ( !aService.getState().equals(nextState)) { stateText = "State changed from " + aService.getState() + " to " + nextState + "."; } //copy characteristics from resource to service //copy characteristics, from resource to service for (org.etsi.osl.tmf.ri639.model.Characteristic rChar : res.getResourceCharacteristic()) { for (org.etsi.osl.tmf.ri639.model.Characteristic rChar : res.getResourceCharacteristic()) { Characteristic cNew = new Characteristic(); Characteristic cNew = new Characteristic(); Loading @@ -1136,15 +1157,16 @@ public class ServiceRepoService { supd.addServiceCharacteristicItem( cNew ); supd.addServiceCharacteristicItem( cNew ); } } if (as.getServiceCharacteristicByName("_DETAILED_NOTES_") != null) { Note n = new Note(); Note n = new Note(); n.setText("Supporting Resource Attribute Changed with id: " + res.getId()); n.setText(stateText + "Supporting Resource changed with id: " + res.getId()); n.setAuthor( "SIM638-API" ); n.setAuthor( "SIM638-API" ); n.setDate( OffsetDateTime.now(ZoneOffset.UTC).toString() ); n.setDate( OffsetDateTime.now(ZoneOffset.UTC).toString() ); supd.addNoteItem( n ); supd.addNoteItem( n ); } this.updateService( aService.getId(), supd , true, null, null); //update the service this.updateService( aService.getId(), supd , true, null, null); //update the service //} } } Loading Loading @@ -1185,47 +1207,23 @@ public class ServiceRepoService { @Transactional @Transactional private void updateServiceFromresourceChange(Resource res) { private void updateServiceFromresourceChange(Resource res) { logger.info("Will update services related to this resource with id = " + res.getId() ); updateServicesHavingThisSupportingResource(res); var aservices = findServicesHavingThisSupportingResourceID(res.getId()); for (Service as : aservices) { Service aService = findByUuid(as.getId()); List<Resource> rlist = new ArrayList<Resource>(); for (ResourceRef rref : aService.getSupportingResource()) { Optional<Resource> result = resourceRepo.findByUuid(rref.getId()); if (result.isPresent()) { rlist.add( result.get() ); } } rlist.add(res); //add also this one addAnyNewRelatedResourcesFromKubernetesLabel(res); ServiceStateType nextState = aService.findNextStateBasedOnSupportingResources(rlist); ServiceUpdate supd = new ServiceUpdate(); supd.setState(nextState); Note n = new Note(); n.setText("Supporting Resource " + res.getId() + " State Changed with status: " + res.getResourceStatus() + ".Next state is " + nextState); 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 } updateResourceFromKubernetesLabel(res); } } /** * This function will try to identify if the resource contains * a characteristic called "org.etsi.osl.serviceId" and will check if there is a related service. * If it is not it's add the resource back to the service. This is useful in kubernetes deployments, * in cases of new resources in a namespace that are related to this service * @param res */ @Transactional @Transactional private void updateResourceFromKubernetesLabel(Resource res) { private void addAnyNewRelatedResourcesFromKubernetesLabel(Resource res) { logger.debug("updateResourceFromKubernetesLabel for: " + res.getName()); logger.debug("updateResourceFromKubernetesLabel for: " + res.getName() + ", version" + res.getResourceVersion()); if (res.getResourceCharacteristicByName("org.etsi.osl.serviceId") != null) { if (res.getResourceCharacteristicByName("org.etsi.osl.serviceId") != null) { Loading src/main/resources/application-testing.yml +7 −0 Original line number Original line Diff line number Diff line Loading @@ -157,6 +157,13 @@ EVENT_RESOURCE_DELETE: "jms:topic:EVENT.SERVICE.RESOURCE" EVENT_RESOURCE_ATTRIBUTE_VALUE_CHANGED: "jms:topic:EVENT.RESOURCE.ATTRCHANGED" EVENT_RESOURCE_ATTRIBUTE_VALUE_CHANGED: "jms:topic:EVENT.RESOURCE.ATTRCHANGED" CATALOG_RESOURCES_OF_PARTNERS: "jms:queue:CATALOG.GET.SERVICESOFPARTNERS" CATALOG_RESOURCES_OF_PARTNERS: "jms:queue:CATALOG.GET.SERVICESOFPARTNERS" #RESOURCE_ACTIVATION CATALOG_ADD_RESOURCEACTIVATION: "jms:queue:CATALOG.ADD.RESOURCEACTIVATION" CATALOG_UPD_RESOURCEACTIVATION: "jms:queue:CATALOG.UPD.RESOURCEACTIVATION" CATALOG_UPDADD_RESOURCEACTIVATION: "jms:queue:CATALOG.UPDADD.RESOURCEACTIVATION" CATALOG_GET_RESOURCEACTIVATION_BY_ID: "jms:queue:CATALOG.GET.RESOURCEACTIVATION" #LCM MESSAGES #LCM MESSAGES CATALOG_GET_LCMRULE_BY_ID: "jms:queue:CATALOG.GET.LCMRULE" CATALOG_GET_LCMRULE_BY_ID: "jms:queue:CATALOG.GET.LCMRULE" CATALOG_GET_LCMRULES_BY_SPECID_PHASE: "jms:queue:CATALOG.GET.LCMRULES_BY_SPECID_PHASE" CATALOG_GET_LCMRULES_BY_SPECID_PHASE: "jms:queue:CATALOG.GET.LCMRULES_BY_SPECID_PHASE" Loading src/main/resources/application.yml +6 −0 Original line number Original line Diff line number Diff line Loading @@ -189,6 +189,12 @@ EVENT_RESOURCE_DELETE: "jms:topic:EVENT.SERVICE.RESOURCE" EVENT_RESOURCE_ATTRIBUTE_VALUE_CHANGED: "jms:topic:EVENT.RESOURCE.ATTRCHANGED" EVENT_RESOURCE_ATTRIBUTE_VALUE_CHANGED: "jms:topic:EVENT.RESOURCE.ATTRCHANGED" CATALOG_RESOURCES_OF_PARTNERS: "jms:queue:CATALOG.GET.SERVICESOFPARTNERS" CATALOG_RESOURCES_OF_PARTNERS: "jms:queue:CATALOG.GET.SERVICESOFPARTNERS" #RESOURCE_ACTIVATION CATALOG_ADD_RESOURCEACTIVATION: "jms:queue:CATALOG.ADD.RESOURCEACTIVATION" CATALOG_UPD_RESOURCEACTIVATION: "jms:queue:CATALOG.UPD.RESOURCEACTIVATION" CATALOG_UPDADD_RESOURCEACTIVATION: "jms:queue:CATALOG.UPDADD.RESOURCEACTIVATION" CATALOG_GET_RESOURCEACTIVATION_BY_ID: "jms:queue:CATALOG.GET.RESOURCEACTIVATION" #LCM MESSAGES #LCM MESSAGES CATALOG_GET_LCMRULE_BY_ID: "jms:queue:CATALOG.GET.LCMRULE" CATALOG_GET_LCMRULE_BY_ID: "jms:queue:CATALOG.GET.LCMRULE" CATALOG_GET_LCMRULES_BY_SPECID_PHASE: "jms:queue:CATALOG.GET.LCMRULES_BY_SPECID_PHASE" CATALOG_GET_LCMRULES_BY_SPECID_PHASE: "jms:queue:CATALOG.GET.LCMRULES_BY_SPECID_PHASE" Loading Loading
src/main/java/org/etsi/osl/tmf/ram702/api/ResourceActivationApiRouteBuilder.java +14 −14 Original line number Original line Diff line number Diff line Loading @@ -46,17 +46,17 @@ public class ResourceActivationApiRouteBuilder extends RouteBuilder { private static final transient Log logger = LogFactory.getLog(ResourceActivationApiRouteBuilder.class.getName()); private static final transient Log logger = LogFactory.getLog(ResourceActivationApiRouteBuilder.class.getName()); @Value("${CATALOG_ADD_RESOURCE}") @Value("${CATALOG_ADD_RESOURCEACTIVATION}") private String CATALOG_ADD_RESOURCE = ""; private String CATALOG_ADD_RESOURCEACTIVATION = ""; @Value("${CATALOG_UPD_RESOURCE}") @Value("${CATALOG_UPD_RESOURCEACTIVATION}") private String CATALOG_UPD_RESOURCE = ""; private String CATALOG_UPD_RESOURCEACTIVATION = ""; @Value("${CATALOG_UPDADD_RESOURCE}") @Value("${CATALOG_UPDADD_RESOURCEACTIVATION}") private String CATALOG_UPDADD_RESOURCE = ""; private String CATALOG_UPDADD_RESOURCEACTIVATION = ""; @Value("${CATALOG_GET_RESOURCE_BY_ID}") @Value("${CATALOG_GET_RESOURCEACTIVATION_BY_ID}") private String CATALOG_GET_RESOURCE_BY_ID = ""; private String CATALOG_GET_RESOURCEACTIVATION_BY_ID = ""; @Autowired @Autowired private ProducerTemplate template; private ProducerTemplate template; Loading @@ -67,8 +67,8 @@ public class ResourceActivationApiRouteBuilder extends RouteBuilder { @Override @Override public void configure() throws Exception { public void configure() throws Exception { from( CATALOG_ADD_RESOURCE ) from( CATALOG_ADD_RESOURCEACTIVATION ) .log(LoggingLevel.INFO, log, CATALOG_ADD_RESOURCE + " message received!") .log(LoggingLevel.INFO, log, CATALOG_ADD_RESOURCEACTIVATION + " message received!") .to("log:DEBUG?showBody=true&showHeaders=true") .to("log:DEBUG?showBody=true&showHeaders=true") .unmarshal().json( JsonLibrary.Jackson, ResourceCreate.class, true) .unmarshal().json( JsonLibrary.Jackson, ResourceCreate.class, true) .bean( resourceRepoService, "addResource(${body})") .bean( resourceRepoService, "addResource(${body})") Loading @@ -76,16 +76,16 @@ public class ResourceActivationApiRouteBuilder extends RouteBuilder { .json( JsonLibrary.Jackson) .json( JsonLibrary.Jackson) .convertBodyTo( String.class ); .convertBodyTo( String.class ); from( CATALOG_UPD_RESOURCE ) from( CATALOG_UPD_RESOURCEACTIVATION ) .log(LoggingLevel.INFO, log, CATALOG_UPD_RESOURCE + " message received!") .log(LoggingLevel.INFO, log, CATALOG_UPD_RESOURCEACTIVATION + " message received!") .to("log:DEBUG?showBody=true&showHeaders=true") .to("log:DEBUG?showBody=true&showHeaders=true") .unmarshal().json( JsonLibrary.Jackson, ResourceUpdate.class, true) .unmarshal().json( JsonLibrary.Jackson, ResourceUpdate.class, true) .bean( resourceRepoService, "updateResource(${header.resourceId}, ${body}, ${header.triggerServiceActionQueue} )") .bean( resourceRepoService, "updateResource(${header.resourceId}, ${body}, ${header.triggerServiceActionQueue} )") .marshal().json( JsonLibrary.Jackson) .marshal().json( JsonLibrary.Jackson) .convertBodyTo( String.class ); .convertBodyTo( String.class ); from( CATALOG_UPDADD_RESOURCE ) from( CATALOG_UPDADD_RESOURCEACTIVATION ) .log(LoggingLevel.INFO, log, CATALOG_UPDADD_RESOURCE + " message received!") .log(LoggingLevel.INFO, log, CATALOG_UPDADD_RESOURCEACTIVATION + " message received!") .to("log:DEBUG?showBody=true&showHeaders=true") .to("log:DEBUG?showBody=true&showHeaders=true") .unmarshal().json( JsonLibrary.Jackson, ResourceCreate.class, true) .unmarshal().json( JsonLibrary.Jackson, ResourceCreate.class, true) .bean( resourceRepoService, "addOrUpdateResourceByNameCategoryVersion(${header.aname},${header.acategory}, ${header.aversion}, ${body})") .bean( resourceRepoService, "addOrUpdateResourceByNameCategoryVersion(${header.aname},${header.acategory}, ${header.aversion}, ${body})") Loading
src/main/java/org/etsi/osl/tmf/ram702/api/ResourceActivationApiRouteBuilderEvents.javadeleted 100644 → 0 +0 −112 Original line number Original line Diff line number Diff line /*- * ========================LICENSE_START================================= * org.etsi.osl.tmf.api * %% * Copyright (C) 2024 openslice.io * %% * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * =========================LICENSE_END================================== */ package org.etsi.osl.tmf.ram702.api; import java.io.IOException; import java.util.HashMap; import java.util.Map; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.databind.ObjectMapper; import org.apache.camel.ProducerTemplate; import org.apache.camel.builder.RouteBuilder; 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.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Configuration; import org.springframework.stereotype.Component; @Configuration // @RefreshScope @Component public class ResourceActivationApiRouteBuilderEvents extends RouteBuilder { private static final transient Log logger = LogFactory.getLog(ResourceActivationApiRouteBuilderEvents.class.getName()); @Value("${EVENT_RESOURCE_CREATE}") private String EVENT_RESOURCE_CREATE = ""; @Value("${EVENT_RESOURCE_STATE_CHANGED}") private String EVENT_RESOURCE_STATE_CHANGED = ""; @Value("${EVENT_RESOURCE_DELETE}") private String EVENT_RESOURCE_DELETE = ""; @Value("${EVENT_RESOURCE_ATTRIBUTE_VALUE_CHANGED}") private String EVENT_RESOURCE_ATTRIBUTE_VALUE_CHANGED = ""; @Autowired private ProducerTemplate template; @Override public void configure() throws Exception { } /** * @param n */ public void publishEvent(final Notification n, final String objId) { n.setEventType(n.getClass().getName()); logger.info("will send Event topic for type " + n.getEventType()); try { String msgtopic = ""; if (n instanceof ResourceCreateNotification) { msgtopic = EVENT_RESOURCE_CREATE; } else if (n instanceof ResourceAttributeValueChangeNotification) { msgtopic = EVENT_RESOURCE_ATTRIBUTE_VALUE_CHANGED; }else if (n instanceof ResourceStateChangeNotification ) { msgtopic = EVENT_RESOURCE_STATE_CHANGED; } Map<String, Object> map = new HashMap<>(); map.put("eventid", n.getEventId()); map.put("objId", objId); template.sendBodyAndHeaders(msgtopic, toJsonString(n), map); } catch (Exception e) { logger.error("Cannot send Event . " + e.getStackTrace()); } } static String toJsonString(Object object) throws IOException { ObjectMapper mapper = new ObjectMapper(); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); return mapper.writeValueAsString(object); } }
src/main/java/org/etsi/osl/tmf/sim638/service/ServiceRepoService.java +56 −58 Original line number Original line Diff line number Diff line Loading @@ -578,11 +578,15 @@ public class ServiceRepoService { } } if (serviceCharacteristicChanged) { if (serviceCharacteristicChanged) { if (service.getServiceCharacteristicByName("_DETAILED_NOTES_") != null) { Note noteItem = new Note(); Note noteItem = new Note(); noteItem.setText("Service Characteristic changed: " + charChangedForNotes ); noteItem.setText("Service Characteristic changed: " + charChangedForNotes ); noteItem.setAuthor("API"); noteItem.setAuthor("SIM638-API"); noteItem.setDate(OffsetDateTime.now(ZoneOffset.UTC) ); noteItem.setDate(OffsetDateTime.now(ZoneOffset.UTC) ); service.addNoteItem(noteItem); service.addNoteItem(noteItem); } } } Loading Loading @@ -1114,20 +1118,37 @@ public class ServiceRepoService { public void updateServicesHavingThisSupportingResource(@Valid Resource res) { public void updateServicesHavingThisSupportingResource(@Valid Resource res) { try { try { logger.info("Will update services related to this resource with id = " + res.getId() ); logger.debug("Will update services related to this resource with id = " + res.getId() ); var aservices = findServicesHavingThisSupportingResourceID( res.getId() ); var aservices = findServicesHavingThisSupportingResourceID( res.getId() ); logger.debug("services.found = " + aservices.size() ); for (Service as : aservices) { for (Service as : aservices) { Service aService = findByUuid(as.getId()); Service aService = findByUuid(as.getId()); //if ( aService.getState().equals( ServiceStateType.ACTIVE ) ) { List<Resource> rlist = new ArrayList<Resource>(); for (ResourceRef rref : aService.getSupportingResource()) { Optional<Resource> result = resourceRepo.findByUuid(rref.getId()); if (result.isPresent()) { rlist.add( result.get() ); } } rlist.add(res); //add also this one ServiceStateType nextState = aService.findNextStateBasedOnSupportingResources(rlist); ServiceUpdate supd = new ServiceUpdate(); ServiceUpdate supd = new ServiceUpdate(); supd.setState(nextState); String stateText=""; if ( !aService.getState().equals(nextState)) { stateText = "State changed from " + aService.getState() + " to " + nextState + "."; } //copy characteristics from resource to service //copy characteristics, from resource to service for (org.etsi.osl.tmf.ri639.model.Characteristic rChar : res.getResourceCharacteristic()) { for (org.etsi.osl.tmf.ri639.model.Characteristic rChar : res.getResourceCharacteristic()) { Characteristic cNew = new Characteristic(); Characteristic cNew = new Characteristic(); Loading @@ -1136,15 +1157,16 @@ public class ServiceRepoService { supd.addServiceCharacteristicItem( cNew ); supd.addServiceCharacteristicItem( cNew ); } } if (as.getServiceCharacteristicByName("_DETAILED_NOTES_") != null) { Note n = new Note(); Note n = new Note(); n.setText("Supporting Resource Attribute Changed with id: " + res.getId()); n.setText(stateText + "Supporting Resource changed with id: " + res.getId()); n.setAuthor( "SIM638-API" ); n.setAuthor( "SIM638-API" ); n.setDate( OffsetDateTime.now(ZoneOffset.UTC).toString() ); n.setDate( OffsetDateTime.now(ZoneOffset.UTC).toString() ); supd.addNoteItem( n ); supd.addNoteItem( n ); } this.updateService( aService.getId(), supd , true, null, null); //update the service this.updateService( aService.getId(), supd , true, null, null); //update the service //} } } Loading Loading @@ -1185,47 +1207,23 @@ public class ServiceRepoService { @Transactional @Transactional private void updateServiceFromresourceChange(Resource res) { private void updateServiceFromresourceChange(Resource res) { logger.info("Will update services related to this resource with id = " + res.getId() ); updateServicesHavingThisSupportingResource(res); var aservices = findServicesHavingThisSupportingResourceID(res.getId()); for (Service as : aservices) { Service aService = findByUuid(as.getId()); List<Resource> rlist = new ArrayList<Resource>(); for (ResourceRef rref : aService.getSupportingResource()) { Optional<Resource> result = resourceRepo.findByUuid(rref.getId()); if (result.isPresent()) { rlist.add( result.get() ); } } rlist.add(res); //add also this one addAnyNewRelatedResourcesFromKubernetesLabel(res); ServiceStateType nextState = aService.findNextStateBasedOnSupportingResources(rlist); ServiceUpdate supd = new ServiceUpdate(); supd.setState(nextState); Note n = new Note(); n.setText("Supporting Resource " + res.getId() + " State Changed with status: " + res.getResourceStatus() + ".Next state is " + nextState); 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 } updateResourceFromKubernetesLabel(res); } } /** * This function will try to identify if the resource contains * a characteristic called "org.etsi.osl.serviceId" and will check if there is a related service. * If it is not it's add the resource back to the service. This is useful in kubernetes deployments, * in cases of new resources in a namespace that are related to this service * @param res */ @Transactional @Transactional private void updateResourceFromKubernetesLabel(Resource res) { private void addAnyNewRelatedResourcesFromKubernetesLabel(Resource res) { logger.debug("updateResourceFromKubernetesLabel for: " + res.getName()); logger.debug("updateResourceFromKubernetesLabel for: " + res.getName() + ", version" + res.getResourceVersion()); if (res.getResourceCharacteristicByName("org.etsi.osl.serviceId") != null) { if (res.getResourceCharacteristicByName("org.etsi.osl.serviceId") != null) { Loading
src/main/resources/application-testing.yml +7 −0 Original line number Original line Diff line number Diff line Loading @@ -157,6 +157,13 @@ EVENT_RESOURCE_DELETE: "jms:topic:EVENT.SERVICE.RESOURCE" EVENT_RESOURCE_ATTRIBUTE_VALUE_CHANGED: "jms:topic:EVENT.RESOURCE.ATTRCHANGED" EVENT_RESOURCE_ATTRIBUTE_VALUE_CHANGED: "jms:topic:EVENT.RESOURCE.ATTRCHANGED" CATALOG_RESOURCES_OF_PARTNERS: "jms:queue:CATALOG.GET.SERVICESOFPARTNERS" CATALOG_RESOURCES_OF_PARTNERS: "jms:queue:CATALOG.GET.SERVICESOFPARTNERS" #RESOURCE_ACTIVATION CATALOG_ADD_RESOURCEACTIVATION: "jms:queue:CATALOG.ADD.RESOURCEACTIVATION" CATALOG_UPD_RESOURCEACTIVATION: "jms:queue:CATALOG.UPD.RESOURCEACTIVATION" CATALOG_UPDADD_RESOURCEACTIVATION: "jms:queue:CATALOG.UPDADD.RESOURCEACTIVATION" CATALOG_GET_RESOURCEACTIVATION_BY_ID: "jms:queue:CATALOG.GET.RESOURCEACTIVATION" #LCM MESSAGES #LCM MESSAGES CATALOG_GET_LCMRULE_BY_ID: "jms:queue:CATALOG.GET.LCMRULE" CATALOG_GET_LCMRULE_BY_ID: "jms:queue:CATALOG.GET.LCMRULE" CATALOG_GET_LCMRULES_BY_SPECID_PHASE: "jms:queue:CATALOG.GET.LCMRULES_BY_SPECID_PHASE" CATALOG_GET_LCMRULES_BY_SPECID_PHASE: "jms:queue:CATALOG.GET.LCMRULES_BY_SPECID_PHASE" Loading
src/main/resources/application.yml +6 −0 Original line number Original line Diff line number Diff line Loading @@ -189,6 +189,12 @@ EVENT_RESOURCE_DELETE: "jms:topic:EVENT.SERVICE.RESOURCE" EVENT_RESOURCE_ATTRIBUTE_VALUE_CHANGED: "jms:topic:EVENT.RESOURCE.ATTRCHANGED" EVENT_RESOURCE_ATTRIBUTE_VALUE_CHANGED: "jms:topic:EVENT.RESOURCE.ATTRCHANGED" CATALOG_RESOURCES_OF_PARTNERS: "jms:queue:CATALOG.GET.SERVICESOFPARTNERS" CATALOG_RESOURCES_OF_PARTNERS: "jms:queue:CATALOG.GET.SERVICESOFPARTNERS" #RESOURCE_ACTIVATION CATALOG_ADD_RESOURCEACTIVATION: "jms:queue:CATALOG.ADD.RESOURCEACTIVATION" CATALOG_UPD_RESOURCEACTIVATION: "jms:queue:CATALOG.UPD.RESOURCEACTIVATION" CATALOG_UPDADD_RESOURCEACTIVATION: "jms:queue:CATALOG.UPDADD.RESOURCEACTIVATION" CATALOG_GET_RESOURCEACTIVATION_BY_ID: "jms:queue:CATALOG.GET.RESOURCEACTIVATION" #LCM MESSAGES #LCM MESSAGES CATALOG_GET_LCMRULE_BY_ID: "jms:queue:CATALOG.GET.LCMRULE" CATALOG_GET_LCMRULE_BY_ID: "jms:queue:CATALOG.GET.LCMRULE" CATALOG_GET_LCMRULES_BY_SPECID_PHASE: "jms:queue:CATALOG.GET.LCMRULES_BY_SPECID_PHASE" CATALOG_GET_LCMRULES_BY_SPECID_PHASE: "jms:queue:CATALOG.GET.LCMRULES_BY_SPECID_PHASE" Loading