diff --git a/src/main/java/org/etsi/osl/osom/configuration/OSOMRouteBuilder.java b/src/main/java/org/etsi/osl/osom/configuration/OSOMRouteBuilder.java index 61d3e4030b2751ac7a9616cd3fb0e608df30fb74..9cddc76578abe059c330241ec2b09677f6f5275f 100644 --- a/src/main/java/org/etsi/osl/osom/configuration/OSOMRouteBuilder.java +++ b/src/main/java/org/etsi/osl/osom/configuration/OSOMRouteBuilder.java @@ -49,7 +49,9 @@ public class OSOMRouteBuilder extends RouteBuilder { @Value("${CRD_DEPLOY_CR_REQ}") private String CRD_DEPLOY_CR_REQ = ""; - + + @Value("${CRD_PATCH_CR_REQ}") + private String CRD_PATCH_CR_REQ = ""; public void configure() { @@ -70,6 +72,20 @@ public class OSOMRouteBuilder extends RouteBuilder { .to(CRD_DEPLOY_CR_REQ); + from("direct:retriesCRD_PATCH_CR_REQ") + .errorHandler(deadLetterChannel("direct:retriesDeadLetters") + .maximumRedeliveries( 10 ) //let's try 10 times to send it.... + .redeliveryDelay( 30000 ).useOriginalMessage() + //.deadLetterHandleNewException( false ) + //.logExhaustedMessageHistory(false) + .logExhausted(true) + .logHandled(true) + //.retriesExhaustedLogLevel(LoggingLevel.WARN) + .retryAttemptedLogLevel( LoggingLevel.WARN) ) + .to(CRD_PATCH_CR_REQ); + + + /** * dead Letter Queue Users if everything fails to connect */ diff --git a/src/main/java/org/etsi/osl/osom/management/ServiceOrderManager.java b/src/main/java/org/etsi/osl/osom/management/ServiceOrderManager.java index 0a09c5f367d8d52263f8a81dbae4fb0777712448..86fb199ed59521d9af7c64df888d3cb35d1bbf9e 100644 --- a/src/main/java/org/etsi/osl/osom/management/ServiceOrderManager.java +++ b/src/main/java/org/etsi/osl/osom/management/ServiceOrderManager.java @@ -1024,7 +1024,36 @@ public class ServiceOrderManager { return null; } + + + + /** + * @param rFS_CRSPEC + * @param serviceId + * + */ + public String cridgeDeploymentUpdateRequest(Map map, String CR_SPEC) { + + + try { + + Object response = template.requestBodyAndHeaders( "direct:retriesCRD_PATCH_CR_REQ", CR_SPEC , map ); + + if ( !(response instanceof String)) { + logger.error("cridgeDeploymentUpdateRequest response object is wrong."); + return null; + } + logger.debug("cridgeDeploymentUpdateRequest response is: " + response); + return (String) response; + + }catch (Exception e) { + logger.error("Cannot retrieve cridgeDeploymentUpdateRequest response. " + e.toString()); + e.printStackTrace(); + } + return null; + + } /** diff --git a/src/main/java/org/etsi/osl/osom/serviceactions/CRPatchTask.java b/src/main/java/org/etsi/osl/osom/serviceactions/CRPatchTask.java index 2e8c65a6bd0391e3d06d40a19fdeb44059632c8a..3d04a14a0e67b13d5e92eb2b61171578fc0819e8 100644 --- a/src/main/java/org/etsi/osl/osom/serviceactions/CRPatchTask.java +++ b/src/main/java/org/etsi/osl/osom/serviceactions/CRPatchTask.java @@ -3,7 +3,9 @@ package org.etsi.osl.osom.serviceactions; import java.time.OffsetDateTime; import java.time.ZoneOffset; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import org.apache.commons.logging.Log; @@ -12,8 +14,10 @@ import org.etsi.osl.osom.management.AlarmsService; import org.etsi.osl.osom.management.ServiceOrderManager; import org.etsi.osl.tmf.common.model.service.Characteristic; import org.etsi.osl.tmf.common.model.service.Note; +import org.etsi.osl.tmf.common.model.service.ResourceRef; import org.etsi.osl.tmf.sim638.model.Service; import org.etsi.osl.tmf.sim638.model.ServiceActionQueueItem; +import org.etsi.osl.tmf.sim638.model.ServiceOrderRef; import org.etsi.osl.tmf.sim638.model.ServiceUpdate; import org.flowable.engine.delegate.DelegateExecution; import org.flowable.engine.delegate.JavaDelegate; @@ -58,17 +62,14 @@ public class CRPatchTask implements JavaDelegate { List changeCharacteristics = new ArrayList<>(); - // send to mano client here: only the modified action! // identify here the characteristics that changed if (aService.getServiceCharacteristic() != null) { for (Characteristic srcChar : aService.getServiceCharacteristic()) { if (originalService.getServiceCharacteristicByName(srcChar.getName()) != null) { - Characteristic origChar = - originalService.getServiceCharacteristicByName(srcChar.getName()); - if ((origChar != null) && (origChar.getValue() != null) - && (origChar.getValue().getValue() != null)) { + Characteristic origChar = originalService.getServiceCharacteristicByName(srcChar.getName()); + if ((origChar != null) && (origChar.getValue() != null) && (srcChar.getValue() != null) && (origChar.getValue().getValue() != null)) { if (!origChar.getValue().getValue().equals(srcChar.getValue().getValue())) { changeCharacteristics.add(srcChar); } @@ -79,16 +80,48 @@ public class CRPatchTask implements JavaDelegate { - Note n = new Note(); - n.setText("Service Action CRPatchTask does nothing for now. Action: " + item.getAction() + ". "); - n.setAuthor(compname); - n.setDate(OffsetDateTime.now(ZoneOffset.UTC).toString()); + ServiceUpdate supd = new ServiceUpdate(); + try { + + String response = null; + Characteristic servicecrspec = aService.getServiceCharacteristicByName("_CR_SPEC"); + String crspec = servicecrspec.getValue().getValue(); + + response = createNewDeploymentUpdateRequest(aService, crspec); + Note n = new Note(); + n.setAuthor(compname); + n.setDate(OffsetDateTime.now(ZoneOffset.UTC).toString()); + if ( response!=null && response.equals("OK")) { + + n.setText("Service Action CRPatchTask successful . Action: " + item.getAction() + ". "); + } else { + n.setText("Service Action CRPatchTask failed . Action: " + item.getAction() + ". Response = " + response); + } + + supd.addNoteItem(n); + serviceOrderManager.deleteServiceActionQueueItem(item); + serviceOrderManager.updateService(aService.getId(), supd, false); + + + return; + + }catch (Exception e) { + e.printStackTrace(); + } + + + + + Note n = new Note(); + n.setText("Service Action CRPatchTask FAILED. Action: " + item.getAction() + ". "); + n.setAuthor(compname); + n.setDate(OffsetDateTime.now(ZoneOffset.UTC).toString()); supd.addNoteItem(n); serviceOrderManager.deleteServiceActionQueueItem(item); serviceOrderManager.updateService(aService.getId(), supd, false); @@ -99,4 +132,52 @@ public class CRPatchTask implements JavaDelegate { } + private String createNewDeploymentUpdateRequest(Service aService, String crspec) { + try { + Map map = new HashMap<>(); + map.put("currentContextCluster",getServiceCharacteristic(aService, "currentContextCluster") ); + map.put("clusterMasterURL",getServiceCharacteristic(aService, "clusterMasterURL") ); + map.put("org.etsi.osl.serviceId", aService.getId() ); + map.put("org.etsi.osl.prefixName",getServiceCharacteristic(aService, "org.etsi.osl.prefixName") ); + map.put("org.etsi.osl.resourceId",getServiceCharacteristic(aService, "org.etsi.osl.resourceId") ); + map.put("org.etsi.osl.serviceOrderId",getServiceCharacteristic(aService, "org.etsi.osl.serviceOrderId") ); + map.put("org.etsi.osl.namespace",getServiceCharacteristic(aService, "org.etsi.osl.namespace") ); + map.put("org.etsi.osl.statusCheckFieldName",getServiceCharacteristic(aService, "org.etsi.osl.statusCheckFieldName") ); + map.put("org.etsi.osl.statusCheckValueStandby",getServiceCharacteristic(aService, "org.etsi.osl.statusCheckValueStandby") ); + map.put("org.etsi.osl.statusCheckValueAlarm",getServiceCharacteristic(aService, "org.etsi.osl.statusCheckValueAlarm") ); + map.put("org.etsi.osl.statusCheckValueAvailable",getServiceCharacteristic(aService, "org.etsi.osl.statusCheckValueAvailable") ); + map.put("org.etsi.osl.statusCheckValueReserved",getServiceCharacteristic(aService, "org.etsi.osl.statusCheckValueReserved") ); + map.put("org.etsi.osl.statusCheckValueUnknown",getServiceCharacteristic(aService, "org.etsi.osl.statusCheckValueUnknown") ); + map.put("org.etsi.osl.statusCheckValueSuspended",getServiceCharacteristic(aService, "org.etsi.osl.statusCheckValueSuspended") ); + + + + + String response = serviceOrderManager.cridgeDeploymentUpdateRequest( map, crspec); + int retries = 0; + while ( response.equals("SEE OTHER")) { + response = serviceOrderManager.cridgeDeploymentUpdateRequest( map, crspec); + Thread.sleep(1000); + retries++; + if (retries>100) { //will support maximum 100 registered CRIDGE in queue + break; + } + } + return response; + + } catch (Exception e) { + logger.error("cridgeDeploymentRequest failed"); + e.printStackTrace(); + } + + return null; + } + + private Object getServiceCharacteristic(Service aService, String val) { + if (aService.getServiceCharacteristicByName( val ) !=null ) { + return aService.getServiceCharacteristicByName( val ).getValue().getValue(); + } + return ""; + } + }