From e31e84996b8909d08b6455bf4e8f69e37a1f17fe Mon Sep 17 00:00:00 2001 From: Christos Tranoris Date: Wed, 18 Dec 2024 10:02:22 +0200 Subject: [PATCH 1/5] fix for #60 --- .../sim638/service/ServiceRepoService.java | 153 ++++++++++++------ 1 file changed, 102 insertions(+), 51 deletions(-) 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 9e7bb03..2202dcf 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 @@ -1155,16 +1155,14 @@ public class ServiceRepoService { public void updateServicesHavingThisSupportingResource(@Valid Resource res) { try { - logger.debug("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() ); - - logger.debug("services.found = " + aservices.size() ); for (Service as : aservices) { - Service aService = findByUuid(as.getId()); - + Service aService = getServiceEager(as.getId()); + + ServiceStateType nextState = aService.getState(); List rlist = new ArrayList(); for (ResourceRef rref : aService.getSupportingResource()) { Optional result = resourceRepo.findByUuid(rref.getId()); @@ -1172,41 +1170,101 @@ public class ServiceRepoService { rlist.add( result.get() ); } } - - rlist.add(res); //add also this one - ServiceStateType nextState = aService.findNextStateBasedOnSupportingResources(rlist); - - 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 + + /* + * Construct characteristic name + */ + String kind = ""; + String resourcename = res.getName() ; + + org.etsi.osl.tmf.ri639.model.Characteristic ckind = res.getResourceCharacteristicByName("Kind"); + if ( ckind != null && ckind.getValue() != null) { + kind = ckind.getValue().getValue() ; //example "ConfigMap" + } + + if ( res.getName().indexOf('@')>0) { + String firstToken = res.getName().substring( 0, res.getName().indexOf('@') ); + resourcename = firstToken ; //example "cr0fc1234-amf" + } + + Boolean resourceIsSameKind = aService.checkIsKindResource(res); + if (resourceIsSameKind) { //if this service is the same kind as the resource then don't prefix the characteristic + kind = ""; + resourcename=""; + //rlist.add(res); //add only this one + }else { + //enable the following to remove crXXXXXX prefix in name +// org.etsi.osl.tmf.ri639.model.Characteristic kubinstance = res.getResourceCharacteristicByName("app.kubernetes.io/instance"); +// if ( kubinstance != null && kubinstance.getValue() != null) { +// String removePrefix = kubinstance.getValue().getValue(); +// resourcename = resourcename.replace( removePrefix + "-", ""); +// resourcename = resourcename.replace( removePrefix, ""); +// } + kind = kind + "."; + resourcename = resourcename + "."; + } + + + + ServiceUpdate supd = new ServiceUpdate(); + nextState = aService.findNextStateBasedOnResourceList(rlist); + supd.setState(nextState); + String stateText=""; + if ( !aService.getState().equals(nextState)) { + stateText = "State changed from " + aService.getState() + " to " + nextState + "."; + logger.debug("====================> stateText = " + stateText); + for (Resource r : rlist) { + logger.debug("==================> s:"+ r.getResourceStatus().name()+ ", name:"+ r.getName() ); + } - - - //copy characteristics, from resource to service - - for (org.etsi.osl.tmf.ri639.model.Characteristic rChar : res.getResourceCharacteristic()) { - Characteristic cNew = new Characteristic(); - cNew.setName( rChar.getName()); - cNew.value( new Any( rChar.getValue() )); - supd.addServiceCharacteristicItem( cNew ); + } + + //adding all characteristics from service + for (Characteristic ch : aService.getServiceCharacteristic()) { + supd.addServiceCharacteristicItem(ch); + } + + + String dontCopyChars = "clusterMasterURL,currentContextCluster,fullResourceName,Kind,apiGroup,UID,metadata"; + String[] arrayDontCopyChars = dontCopyChars.split(","); + Set setB = new HashSet<>(Arrays.asList(arrayDontCopyChars)); + for (org.etsi.osl.tmf.ri639.model.Characteristic rChar : res.getResourceCharacteristic()) { + if ( resourceIsSameKind || ( !setB.contains( rChar.getName()) && !rChar.getName().startsWith("org.etsi.osl") ) ){ //don;t copy characteristics in set + if ( rChar.getValue() != null ) { + + String characteristicname = kind + resourcename + rChar.getName(); + if ( supd.getServiceCharacteristicByName( characteristicname ) != null ) { + supd.getServiceCharacteristicByName( characteristicname ) .value(new Any( rChar.getValue() )); + } else { + Characteristic cNew = new Characteristic(); + cNew.setName( characteristicname ); + cNew.value( new Any( rChar.getValue() )); + supd.addServiceCharacteristicItem( cNew ); + + } + + + } } + + } + - Characteristic noteCheck = as.getServiceCharacteristicByName("_DETAILED_NOTES_"); - if ( noteCheck!= null - && noteCheck.getValue() != null - && noteCheck.getValue().getValue() != null - && !noteCheck.getValue().getValue().equals("")) { - Note n = new Note(); - n.setText(stateText + "Supporting Resource changed with id: " + res.getId()); - 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 + Characteristic noteCheck = as.getServiceCharacteristicByName("_DETAILED_NOTES_"); + if ( noteCheck!= null + && noteCheck.getValue() != null + && noteCheck.getValue().getValue() != null + && !noteCheck.getValue().getValue().equals("")) { + Note n = new Note(); + n.setText(stateText + "Supporting Resource changed with id: " + res.getId()); + 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 } @@ -1218,6 +1276,8 @@ public class ServiceRepoService { } + + @Transactional public void resourceCreatedEvent(@Valid ResourceCreateNotification resNotif) { try { @@ -1247,12 +1307,10 @@ public class ServiceRepoService { @Transactional private void updateServiceFromresourceChange(Resource res) { - + + addAnyNewRelatedResourcesFromKubernetesLabel(res); updateServicesHavingThisSupportingResource(res); - - addAnyNewRelatedResourcesFromKubernetesLabel(res); - - + } /** @@ -1273,7 +1331,7 @@ public class ServiceRepoService { String serviceId = res.getResourceCharacteristicByName("org.etsi.osl.serviceId").getValue().getValue(); logger.debug("rserviceId: " + serviceId); - Service aService = findByUuid( serviceId ); + Service aService = getServiceEager( serviceId ); if ( aService !=null ) { logger.debug("aService found "); Boolean resourceFoundInSupportedResourcesOfService = false; @@ -1292,14 +1350,7 @@ public class ServiceRepoService { rref.id(res.getId()).name(res.getName()); supd.addSupportingResourceItem(rref ); - //copy characteristics from resource to service - for (org.etsi.osl.tmf.ri639.model.Characteristic rChar : res.getResourceCharacteristic()) { - Characteristic cNew = new Characteristic(); - cNew.setName( rChar.getName()); - cNew.value( new Any( rChar.getValue() )); - supd.addServiceCharacteristicItem( cNew ); - } - + Note n = new Note(); n.setText("Supporting Resource "+ res.getId() + " Added in service" ); -- GitLab From 09544bf4785e05eac71f6fc898cda7813080e432 Mon Sep 17 00:00:00 2001 From: Christos Tranoris Date: Wed, 18 Dec 2024 14:48:36 +0200 Subject: [PATCH 2/5] fix for #60 --- .../ri639/api/ResourceApiRouteBuilder.java | 10 +- .../sim638/api/ServiceApiRouteBuilder.java | 24 +-- .../sim638/service/ServiceRepoService.java | 144 ++++++++++++++---- 3 files changed, 134 insertions(+), 44 deletions(-) diff --git a/src/main/java/org/etsi/osl/tmf/ri639/api/ResourceApiRouteBuilder.java b/src/main/java/org/etsi/osl/tmf/ri639/api/ResourceApiRouteBuilder.java index fc6252f..bc445f1 100644 --- a/src/main/java/org/etsi/osl/tmf/ri639/api/ResourceApiRouteBuilder.java +++ b/src/main/java/org/etsi/osl/tmf/ri639/api/ResourceApiRouteBuilder.java @@ -74,7 +74,7 @@ public class ResourceApiRouteBuilder extends RouteBuilder { public void configure() throws Exception { from( CATALOG_ADD_RESOURCE ) - .log(LoggingLevel.INFO, log, CATALOG_ADD_RESOURCE + " message received!") + .log(LoggingLevel.DEBUG, log, CATALOG_ADD_RESOURCE + " message received!") .to("log:DEBUG?showBody=true&showHeaders=true") .unmarshal().json( JsonLibrary.Jackson, ResourceCreate.class, true) .bean( resourceRepoService, "addResource(${body})") @@ -83,13 +83,13 @@ public class ResourceApiRouteBuilder extends RouteBuilder { .convertBodyTo( String.class ); from( CATALOG_GET_RESOURCE_BY_ID ) - .log(LoggingLevel.INFO, log, CATALOG_GET_RESOURCE_BY_ID + " message received!") + .log(LoggingLevel.DEBUG, log, CATALOG_GET_RESOURCE_BY_ID + " message received!") .to("log:DEBUG?showBody=true&showHeaders=true") .bean( resourceRepoService, "getResourceEagerAsString") .convertBodyTo( String.class ); from( CATALOG_UPD_RESOURCE ) - .log(LoggingLevel.INFO, log, CATALOG_UPD_RESOURCE + " message received!") + .log(LoggingLevel.DEBUG, log, CATALOG_UPD_RESOURCE + " message received!") .to("log:DEBUG?showBody=true&showHeaders=true") .unmarshal().json( JsonLibrary.Jackson, ResourceUpdate.class, true) .bean( resourceRepoService, "updateResource(${header.resourceId}, ${body}, ${header.triggerServiceActionQueue} )") @@ -97,14 +97,14 @@ public class ResourceApiRouteBuilder extends RouteBuilder { .convertBodyTo( String.class ); from( CATALOG_RESOURCES_OF_PARTNERS ) - .log(LoggingLevel.INFO, log, CATALOG_RESOURCES_OF_PARTNERS + " message received!") + .log(LoggingLevel.DEBUG, log, CATALOG_RESOURCES_OF_PARTNERS + " message received!") .to("log:DEBUG?showBody=true&showHeaders=true") .bean( resourceRepoService, "findAllActiveAndReservedResourcesOfPartners") .marshal().json( JsonLibrary.Jackson) .convertBodyTo( String.class ); from( CATALOG_UPDADD_RESOURCE ) - .log(LoggingLevel.INFO, log, CATALOG_UPDADD_RESOURCE + " message received!") + .log(LoggingLevel.DEBUG, log, CATALOG_UPDADD_RESOURCE + " message received!") .to("log:DEBUG?showBody=true&showHeaders=true") .unmarshal().json( JsonLibrary.Jackson, ResourceCreate.class, true) .bean( resourceRepoService, "addOrUpdateResourceByNameCategoryVersion(${header.aname},${header.acategory}, ${header.aversion}, ${body})") 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 b1e6877..84645c5 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 @@ -123,7 +123,7 @@ public class ServiceApiRouteBuilder extends RouteBuilder { from( CATALOG_ADD_SERVICE ) - .log(LoggingLevel.INFO, log, CATALOG_ADD_SERVICE + " message received and will be processed for service inventory!") + .log(LoggingLevel.DEBUG, log, CATALOG_ADD_SERVICE + " message received and will be processed for service inventory!") .to("log:DEBUG?showBody=true&showHeaders=true") .unmarshal().json( JsonLibrary.Jackson, ServiceCreate.class, true) .bean( serviceRepoService, "addService(${body})") @@ -131,7 +131,7 @@ public class ServiceApiRouteBuilder extends RouteBuilder { .convertBodyTo( String.class ); from( CATALOG_GET_SERVICE_BY_ID ) - .log(LoggingLevel.INFO, log, CATALOG_GET_SERVICE_BY_ID + " message received and will be processed for service inventory!") + .log(LoggingLevel.DEBUG, log, CATALOG_GET_SERVICE_BY_ID + " message received and will be processed for service inventory!") .to("log:DEBUG?showBody=true&showHeaders=true") .bean( serviceRepoService, "getServiceEagerAsString") .convertBodyTo( String.class ); @@ -139,7 +139,7 @@ public class ServiceApiRouteBuilder extends RouteBuilder { from( CATALOG_UPD_SERVICE ) - .log(LoggingLevel.INFO, log, CATALOG_UPD_SERVICE + " message received and will be processed for service inventory!") + .log(LoggingLevel.DEBUG, log, CATALOG_UPD_SERVICE + " message received and will be processed for service inventory!") .to("log:DEBUG?showBody=true&showHeaders=true") .unmarshal().json( JsonLibrary.Jackson, ServiceUpdate.class, true) .bean( serviceRepoService, "updateService(${header.serviceid}, ${body}, ${header.triggerServiceActionQueue} )") @@ -148,14 +148,14 @@ public class ServiceApiRouteBuilder extends RouteBuilder { from( CATALOG_SERVICE_QUEUE_ITEMS_GET ) - .log(LoggingLevel.INFO, log, CATALOG_SERVICE_QUEUE_ITEMS_GET + " message received and will be processed for service inventory!") + .log(LoggingLevel.DEBUG, log, CATALOG_SERVICE_QUEUE_ITEMS_GET + " message received and will be processed for service inventory!") .to("log:DEBUG?showBody=true&showHeaders=true") .bean( serviceRepoService, "findAllServiceActionQueueItems") .marshal().json( JsonLibrary.Jackson) .convertBodyTo( String.class ); from( CATALOG_SERVICE_QUEUE_ITEM_UPD ) - .log(LoggingLevel.INFO, log, CATALOG_SERVICE_QUEUE_ITEM_UPD + " message received and will be processed for service inventory!") + .log(LoggingLevel.DEBUG, log, CATALOG_SERVICE_QUEUE_ITEM_UPD + " message received and will be processed for service inventory!") .to("log:DEBUG?showBody=true&showHeaders=true") .unmarshal().json( JsonLibrary.Jackson, ServiceActionQueueItem.class, true) .bean( serviceRepoService, "updateServiceActionQueueItem(${body})") @@ -163,7 +163,7 @@ public class ServiceApiRouteBuilder extends RouteBuilder { .convertBodyTo( String.class ); from( CATALOG_SERVICE_QUEUE_ITEM_DELETE ) - .log(LoggingLevel.INFO, log, CATALOG_SERVICE_QUEUE_ITEM_DELETE + " message received and will be processed for service inventory!") + .log(LoggingLevel.DEBUG, log, CATALOG_SERVICE_QUEUE_ITEM_DELETE + " message received and will be processed for service inventory!") .to("log:DEBUG?showBody=true&showHeaders=true") .unmarshal().json( JsonLibrary.Jackson, ServiceActionQueueItem.class, true) .bean( serviceRepoService, "deleteServiceActionQueueItemByUuid(${header.itemid})"); @@ -171,7 +171,7 @@ public class ServiceApiRouteBuilder extends RouteBuilder { from( CATALOG_SERVICES_TO_TERMINATE ) - .log(LoggingLevel.INFO, log, CATALOG_SERVICES_TO_TERMINATE + " message received and will be processed for service inventory!") + .log(LoggingLevel.DEBUG, log, CATALOG_SERVICES_TO_TERMINATE + " message received and will be processed for service inventory!") .to("log:DEBUG?showBody=true&showHeaders=true") .bean( serviceRepoService, "findAllActiveServicesToTerminate") .marshal().json( JsonLibrary.Jackson) @@ -179,7 +179,7 @@ public class ServiceApiRouteBuilder extends RouteBuilder { from( CATALOG_SERVICES_OF_PARTNERS ) - .log(LoggingLevel.INFO, log, CATALOG_SERVICES_OF_PARTNERS + " message received and will be processed for service inventory!") + .log(LoggingLevel.DEBUG, log, CATALOG_SERVICES_OF_PARTNERS + " message received and will be processed for service inventory!") .to("log:DEBUG?showBody=true&showHeaders=true") .bean( serviceRepoService, "findAllActiveAndReservedServicesOfPartners") .marshal().json( JsonLibrary.Jackson) @@ -187,14 +187,14 @@ public class ServiceApiRouteBuilder extends RouteBuilder { from( CATALOG_GET_SERVICE_BY_ORDERID ) - .log(LoggingLevel.INFO, log, CATALOG_GET_SERVICE_BY_ORDERID + " message received and will be processed for service inventory!") + .log(LoggingLevel.DEBUG, log, CATALOG_GET_SERVICE_BY_ORDERID + " message received and will be processed for service inventory!") .to("log:DEBUG?showBody=true&showHeaders=true") .bean( serviceRepoService, "getServicesFromOrderID") .marshal().json( JsonLibrary.Jackson) .convertBodyTo( String.class ); from( NFV_CATALOG_NS_LCMCHANGED ) - .log(LoggingLevel.INFO, log, NFV_CATALOG_NS_LCMCHANGED + " message received and will be processed for service inventory!") + .log(LoggingLevel.DEBUG, log, NFV_CATALOG_NS_LCMCHANGED + " message received and will be processed for service inventory!") .to("log:DEBUG?showBody=true&showHeaders=true") .unmarshal().json( JsonLibrary.Jackson, DeploymentDescriptor.class, true) .bean( serviceRepoService, "nfvCatalogNSResourceChanged(${body})"); @@ -202,7 +202,7 @@ public class ServiceApiRouteBuilder extends RouteBuilder { from( EVENT_RESOURCE_STATE_CHANGED ) - .log(LoggingLevel.INFO, log, EVENT_RESOURCE_STATE_CHANGED + " message received and will be processed for service inventory!") + .log(LoggingLevel.DEBUG, log, EVENT_RESOURCE_STATE_CHANGED + " message received and will be processed for service inventory!") .to("log:DEBUG?showBody=true&showHeaders=true") .unmarshal().json( JsonLibrary.Jackson, ResourceStateChangeNotification.class, true) .bean( serviceRepoService, "resourceStateChangedEvent(${body})"); @@ -216,7 +216,7 @@ public class ServiceApiRouteBuilder extends RouteBuilder { .logHandled(true) .retriesExhaustedLogLevel(LoggingLevel.ERROR) .retryAttemptedLogLevel(LoggingLevel.ERROR)) - .log(LoggingLevel.INFO, log, EVENT_RESOURCE_CREATE + " message received and will be processed for service inventory!") + .log(LoggingLevel.DEBUG, 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})"); 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 2202dcf..1f17c69 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 @@ -341,7 +341,24 @@ public class ServiceRepoService { s.addNoteItem(noteItem); - s = this.serviceRepo.save( s ); + int cnt = 0; + if ( service.getServiceCharacteristic()!=null) + for (Characteristic ch : service.getServiceCharacteristic()) { + if ( ch.getName().equals( "org.etsi.osl.prefixName" ) ) { + cnt++; + } + if ( ch.getName().equals( "AdditionPropertiesAsJson" ) ) { + logger.debug("=============================================> FOUND CHARACTERISTIC addService AdditionPropertiesAsJson IN addService" ); + logger.debug("=============================================> AdditionPropertiesAsJson charlength=" + ch.getValue().getValue().length() ); + } + } + + if ( cnt>1) { + logger.debug("=============================================> FOUND CHARACTERISTIC TWICE AFTER service addService" ); + + } + + s = this.serviceRepo.save( s ); raiseServiceCreateNotification(s); return s; @@ -394,7 +411,41 @@ public class ServiceRepoService { } - + int cnt = 0; + if ( servUpd.getServiceCharacteristic() != null ) { + for (Characteristic ch1 : servUpd.getServiceCharacteristic()) { + if ( ch1.getName().equals( "org.etsi.osl.prefixName" ) ) { + cnt++; + } + if ( ch1.getName().equals( "AdditionPropertiesAsJson" ) ) { + logger.debug("=============================================> FOUND CHARACTERISTIC AdditionPropertiesAsJson IN servUpd" ); + logger.debug("=============================================> AdditionPropertiesAsJson charlength=" + ch1.getValue().getValue().length() ); + } + + } + + if ( cnt>1) { + logger.debug("=============================================> FOUND CHARACTERISTIC TWICE servUpd updateService servUpd" ); + + } + } + cnt = 0; + for (Characteristic ch : service.getServiceCharacteristic()) { + if ( ch.getName().equals( "org.etsi.osl.prefixName" ) ) { + cnt++; + } + if ( ch.getName().equals( "AdditionPropertiesAsJson" ) ) { + logger.debug("=============================================> FOUND CHARACTERISTIC AdditionPropertiesAsJson IN service" ); + logger.debug("=============================================> AdditionPropertiesAsJson charlength=" + ch.getValue().getValue().length() ); + } + } + + if ( cnt>1) { + logger.debug("=============================================> FOUND CHARACTERISTIC TWICE service updateService service" ); + + } + + if (servUpd.getType()!=null) { service.setType(servUpd.getType()); } @@ -536,7 +587,16 @@ public class ServiceRepoService { } else { service.addServiceCharacteristicItem(n); - + if ( n.getName().equals( "AdditionPropertiesAsJson" ) ) { + logger.debug("=============================================> ADDING AdditionPropertiesAsJson to service" ); + if ( n.getValue()!=null ) { + logger.debug("=============================================> ADDING AdditionPropertiesAsJson charlength=" + n.getValue().getValue().length() ); + } else { + + logger.debug("=============================================> ADDING AdditionPropertiesAsJson charlength=NULL" ); + } + + } if ( !n.getName().contains("::") ) { //it is not a child characteristic serviceCharacteristicChanged = true; charChangedForNotes += n.getName() + ", "; @@ -613,6 +673,7 @@ public class ServiceRepoService { if (charChangedForNotes.contains( "reconciledAt") ) { //this is just a sync message, so we need to igore such changes serviceCharacteristicChanged = false; + logger.debug("=============================================> Just reconciledAt changed" ); } if (serviceCharacteristicChanged) { @@ -634,7 +695,22 @@ public class ServiceRepoService { service = this.serviceRepo.save( service ); - + cnt = 0; + for (Characteristic ch : service.getServiceCharacteristic()) { + if ( ch.getName().equals( "org.etsi.osl.prefixName" ) ) { + cnt++; + } + if ( ch.getName().equals( "AdditionPropertiesAsJson" ) ) { + logger.debug("=============================================> FOUND CHARACTERISTIC AFTER AdditionPropertiesAsJson IN service" ); + logger.debug("=============================================> AdditionPropertiesAsJson charlength=" + ch.getValue().getValue().length() ); + } + } + + if ( cnt>1) { + logger.debug("=============================================> FOUND CHARACTERISTIC TWICE AFTER service updateService service" ); + + } + String requestedServiceAsJson = null; try { requestedServiceAsJson = mapper.writeValueAsString( service ); @@ -778,7 +854,8 @@ public class ServiceRepoService { // } catch (FileNotFoundException e) { // // TODO Auto-generated catch block // e.printStackTrace(); -// } +// } + logger.info("======================================================================================================"); } return service; @@ -894,10 +971,10 @@ public class ServiceRepoService { if ( schart!= null ) { String teest = schart.getValue().getValue(); - logger.debug("schart size = " + teest.length() ); + logger.info("schart size = " + teest.length() ); - logger.debug("schart " + teest ); - logger.debug("======================================================================================================"); + logger.info("schart " + teest ); + logger.info("======================================================================================================"); } return res; @@ -1207,16 +1284,17 @@ public class ServiceRepoService { } - + Boolean stateChaged = false; ServiceUpdate supd = new ServiceUpdate(); nextState = aService.findNextStateBasedOnResourceList(rlist); supd.setState(nextState); String stateText=""; if ( !aService.getState().equals(nextState)) { + stateChaged = true; stateText = "State changed from " + aService.getState() + " to " + nextState + "."; logger.debug("====================> stateText = " + stateText); for (Resource r : rlist) { - logger.debug("==================> s:"+ r.getResourceStatus().name()+ ", name:"+ r.getName() ); + logger.debug("==================> r:{}, state:{} ="+ r.getName() + ", "+ r.getResourceStatus().name()); } } @@ -1224,9 +1302,11 @@ public class ServiceRepoService { //adding all characteristics from service for (Characteristic ch : aService.getServiceCharacteristic()) { supd.addServiceCharacteristicItem(ch); + + } - + Boolean characteristicFoundDifferent =false; String dontCopyChars = "clusterMasterURL,currentContextCluster,fullResourceName,Kind,apiGroup,UID,metadata"; String[] arrayDontCopyChars = dontCopyChars.split(","); Set setB = new HashSet<>(Arrays.asList(arrayDontCopyChars)); @@ -1235,14 +1315,21 @@ public class ServiceRepoService { if ( rChar.getValue() != null ) { String characteristicname = kind + resourcename + rChar.getName(); - if ( supd.getServiceCharacteristicByName( characteristicname ) != null ) { - supd.getServiceCharacteristicByName( characteristicname ) .value(new Any( rChar.getValue() )); + Characteristic servChar = supd.getServiceCharacteristicByName( characteristicname ); + if ( servChar != null && servChar.getValue() != null) { + if (! servChar.getValue().getValue().equals( rChar.getValue().getValue() ) ) { + characteristicFoundDifferent = true; + supd.getServiceCharacteristicByName( characteristicname ) .value(new Any( rChar.getValue() )); + logger.debug("====================> add characteristic: " + characteristicname +", value: "+ rChar.getValue().getValue()); + } + } else { Characteristic cNew = new Characteristic(); cNew.setName( characteristicname ); cNew.value( new Any( rChar.getValue() )); supd.addServiceCharacteristicItem( cNew ); - + characteristicFoundDifferent = true; + logger.debug("====================> add New characteristic: " + characteristicname +", value: "+ rChar.getValue().getValue()); } @@ -1252,19 +1339,22 @@ public class ServiceRepoService { } - Characteristic noteCheck = as.getServiceCharacteristicByName("_DETAILED_NOTES_"); - if ( noteCheck!= null - && noteCheck.getValue() != null - && noteCheck.getValue().getValue() != null - && !noteCheck.getValue().getValue().equals("")) { - Note n = new Note(); - n.setText(stateText + "Supporting Resource changed with id: " + res.getId()); - 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 ( stateChaged || characteristicFoundDifferent) { + Characteristic noteCheck = as.getServiceCharacteristicByName("_DETAILED_NOTES_"); + if ( noteCheck!= null + && noteCheck.getValue() != null + && noteCheck.getValue().getValue() != null + && !noteCheck.getValue().getValue().equals("")) { + Note n = new Note(); + n.setText(stateText + "Supporting Resource changed with id: " + res.getId()); + 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 + + } } -- GitLab From 80d9cb4e3fb226056b48301ce0e202977b0330ec Mon Sep 17 00:00:00 2001 From: Christos Tranoris Date: Thu, 19 Dec 2024 00:26:05 +0200 Subject: [PATCH 3/5] fix for #60. Ignoring prefix chars for services with no Kind --- .../org/etsi/osl/tmf/sim638/service/ServiceRepoService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 1f17c69..44ff8c1 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 @@ -1266,7 +1266,7 @@ public class ServiceRepoService { resourcename = firstToken ; //example "cr0fc1234-amf" } - Boolean resourceIsSameKind = aService.checkIsKindResource(res); + Boolean resourceIsSameKind = aService.checkIsKindResource(res) || aService.getServiceCharacteristicByName("Kind")==null; //either Kind is the same or simply does not exist. Then behave the same if (resourceIsSameKind) { //if this service is the same kind as the resource then don't prefix the characteristic kind = ""; resourcename=""; -- GitLab From 55ce2ecf2573240f0b7660442d92dbbdd630cf15 Mon Sep 17 00:00:00 2001 From: trantzas Date: Thu, 19 Dec 2024 10:33:36 +0000 Subject: [PATCH 4/5] code housekeeping --- .../sim638/service/ServiceRepoService.java | 179 +++++++++--------- 1 file changed, 86 insertions(+), 93 deletions(-) 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 44ff8c1..b439bc9 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 @@ -340,23 +340,25 @@ public class ServiceRepoService { noteItem.setDate(OffsetDateTime.now(ZoneOffset.UTC) ); s.addNoteItem(noteItem); - - int cnt = 0; - if ( service.getServiceCharacteristic()!=null) - for (Characteristic ch : service.getServiceCharacteristic()) { - if ( ch.getName().equals( "org.etsi.osl.prefixName" ) ) { - cnt++; - } - if ( ch.getName().equals( "AdditionPropertiesAsJson" ) ) { - logger.debug("=============================================> FOUND CHARACTERISTIC addService AdditionPropertiesAsJson IN addService" ); - logger.debug("=============================================> AdditionPropertiesAsJson charlength=" + ch.getValue().getValue().length() ); - } - } - - if ( cnt>1) { - logger.debug("=============================================> FOUND CHARACTERISTIC TWICE AFTER service addService" ); + // double characteristic investigation + // + // + // int cnt = 0; + // if ( service.getServiceCharacteristic()!=null) + // for (Characteristic ch : service.getServiceCharacteristic()) { + // if ( ch.getName().equals( "org.etsi.osl.prefixName" ) ) { + // cnt++; + // } + // if ( ch.getName().equals( "AdditionPropertiesAsJson" ) ) { + // logger.debug("=============================================> FOUND CHARACTERISTIC addService AdditionPropertiesAsJson IN addService" ); + // logger.debug("=============================================> AdditionPropertiesAsJson charlength=" + ch.getValue().getValue().length() ); + // } + // } + + // if ( cnt>1) { + // logger.debug("=============================================> FOUND CHARACTERISTIC TWICE AFTER service addService" ); - } + // } s = this.serviceRepo.save( s ); @@ -410,40 +412,42 @@ public class ServiceRepoService { e.printStackTrace(); } - - int cnt = 0; - if ( servUpd.getServiceCharacteristic() != null ) { - for (Characteristic ch1 : servUpd.getServiceCharacteristic()) { - if ( ch1.getName().equals( "org.etsi.osl.prefixName" ) ) { - cnt++; - } - if ( ch1.getName().equals( "AdditionPropertiesAsJson" ) ) { - logger.debug("=============================================> FOUND CHARACTERISTIC AdditionPropertiesAsJson IN servUpd" ); - logger.debug("=============================================> AdditionPropertiesAsJson charlength=" + ch1.getValue().getValue().length() ); - } + // double characteristic investigation + // + // + // int cnt = 0; + // if ( servUpd.getServiceCharacteristic() != null ) { + // for (Characteristic ch1 : servUpd.getServiceCharacteristic()) { + // if ( ch1.getName().equals( "org.etsi.osl.prefixName" ) ) { + // cnt++; + // } + // if ( ch1.getName().equals( "AdditionPropertiesAsJson" ) ) { + // logger.debug("=============================================> FOUND CHARACTERISTIC AdditionPropertiesAsJson IN servUpd" ); + // logger.debug("=============================================> AdditionPropertiesAsJson charlength=" + ch1.getValue().getValue().length() ); + // } - } + // } - if ( cnt>1) { - logger.debug("=============================================> FOUND CHARACTERISTIC TWICE servUpd updateService servUpd" ); + // if ( cnt>1) { + // logger.debug("=============================================> FOUND CHARACTERISTIC TWICE servUpd updateService servUpd" ); - } - } - cnt = 0; - for (Characteristic ch : service.getServiceCharacteristic()) { - if ( ch.getName().equals( "org.etsi.osl.prefixName" ) ) { - cnt++; - } - if ( ch.getName().equals( "AdditionPropertiesAsJson" ) ) { - logger.debug("=============================================> FOUND CHARACTERISTIC AdditionPropertiesAsJson IN service" ); - logger.debug("=============================================> AdditionPropertiesAsJson charlength=" + ch.getValue().getValue().length() ); - } - } - - if ( cnt>1) { - logger.debug("=============================================> FOUND CHARACTERISTIC TWICE service updateService service" ); + // } + // } + // cnt = 0; + // for (Characteristic ch : service.getServiceCharacteristic()) { + // if ( ch.getName().equals( "org.etsi.osl.prefixName" ) ) { + // cnt++; + // } + // if ( ch.getName().equals( "AdditionPropertiesAsJson" ) ) { + // logger.debug("=============================================> FOUND CHARACTERISTIC AdditionPropertiesAsJson IN service" ); + // logger.debug("=============================================> AdditionPropertiesAsJson charlength=" + ch.getValue().getValue().length() ); + // } + // } + + // if ( cnt>1) { + // logger.debug("=============================================> FOUND CHARACTERISTIC TWICE service updateService service" ); - } + // } if (servUpd.getType()!=null) { @@ -587,16 +591,19 @@ public class ServiceRepoService { } else { service.addServiceCharacteristicItem(n); - if ( n.getName().equals( "AdditionPropertiesAsJson" ) ) { - logger.debug("=============================================> ADDING AdditionPropertiesAsJson to service" ); - if ( n.getValue()!=null ) { - logger.debug("=============================================> ADDING AdditionPropertiesAsJson charlength=" + n.getValue().getValue().length() ); - } else { - - logger.debug("=============================================> ADDING AdditionPropertiesAsJson charlength=NULL" ); - } + // double characteristic investigation + // + // + // if ( n.getName().equals( "AdditionPropertiesAsJson" ) ) { + // logger.debug("=============================================> ADDING AdditionPropertiesAsJson to service" ); + // if ( n.getValue()!=null ) { + // logger.debug("=============================================> ADDING AdditionPropertiesAsJson charlength=" + n.getValue().getValue().length() ); + // } else { + + // logger.debug("=============================================> ADDING AdditionPropertiesAsJson charlength=NULL" ); + // } - } + // } if ( !n.getName().contains("::") ) { //it is not a child characteristic serviceCharacteristicChanged = true; charChangedForNotes += n.getName() + ", "; @@ -695,21 +702,24 @@ public class ServiceRepoService { service = this.serviceRepo.save( service ); - cnt = 0; - for (Characteristic ch : service.getServiceCharacteristic()) { - if ( ch.getName().equals( "org.etsi.osl.prefixName" ) ) { - cnt++; - } - if ( ch.getName().equals( "AdditionPropertiesAsJson" ) ) { - logger.debug("=============================================> FOUND CHARACTERISTIC AFTER AdditionPropertiesAsJson IN service" ); - logger.debug("=============================================> AdditionPropertiesAsJson charlength=" + ch.getValue().getValue().length() ); - } - } - - if ( cnt>1) { - logger.debug("=============================================> FOUND CHARACTERISTIC TWICE AFTER service updateService service" ); + // double characteristic investigation + // + // + // cnt = 0; + // for (Characteristic ch : service.getServiceCharacteristic()) { + // if ( ch.getName().equals( "org.etsi.osl.prefixName" ) ) { + // cnt++; + // } + // if ( ch.getName().equals( "AdditionPropertiesAsJson" ) ) { + // logger.debug("=============================================> FOUND CHARACTERISTIC AFTER AdditionPropertiesAsJson IN service" ); + // logger.debug("=============================================> AdditionPropertiesAsJson charlength=" + ch.getValue().getValue().length() ); + // } + // } + + // if ( cnt>1) { + // logger.debug("=============================================> FOUND CHARACTERISTIC TWICE AFTER service updateService service" ); - } + // } String requestedServiceAsJson = null; try { @@ -841,23 +851,6 @@ public class ServiceRepoService { } - Characteristic schart = service.getServiceCharacteristicByName("long_string"); - - if ( schart!= null ) { - String teest = schart.getValue().getValue(); - logger.info("schart size = " + teest.length() ); - - logger.info("schart " + teest ); - System.out.println("The value is : \n " + teest); -// try (PrintWriter out = new PrintWriter("C:\\tranoris\\ctranup\\personal\\Invoices\\filename.txt")) { -// out.println( teest ); -// } catch (FileNotFoundException e) { -// // TODO Auto-generated catch block -// e.printStackTrace(); -// } - logger.info("======================================================================================================"); - } - return service; } @@ -967,15 +960,15 @@ public class ServiceRepoService { String res = mapper.writeValueAsString(s); - Characteristic schart = s.getServiceCharacteristicByName("long_string"); + // Characteristic schart = s.getServiceCharacteristicByName("long_string"); - if ( schart!= null ) { - String teest = schart.getValue().getValue(); - logger.info("schart size = " + teest.length() ); + // if ( schart!= null ) { + // String teest = schart.getValue().getValue(); + // logger.debug("schart size = " + teest.length() ); - logger.info("schart " + teest ); - logger.info("======================================================================================================"); - } + // logger.debug("schart " + teest ); + // logger.debug("======================================================================================================"); + // } return res; } -- GitLab From edb211d4f9f2439f52ef266a6c91e934df4835e4 Mon Sep 17 00:00:00 2001 From: Christos Tranoris Date: Thu, 19 Dec 2024 15:01:21 +0200 Subject: [PATCH 5/5] fix for #60 --- .../org/etsi/osl/services/api/sim638/ServiceRepoServiceTest.java | 1 + 1 file changed, 1 insertion(+) 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 0124945..99e752a 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 @@ -247,6 +247,7 @@ public class ServiceRepoServiceTest { ResourceRef firstResourceRef = resourceRefList.get(0); Resource resource = resourceRepoService.findByUuid(firstResourceRef.getId()); + resource.setResourceStatus(ResourceStatusType.STANDBY); ResourceStateChangeNotification resourceCreateNotification = new ResourceStateChangeNotification(); ResourceStateChangeEvent event = new ResourceStateChangeEvent(); -- GitLab