Skip to content
Snippets Groups Projects
Commit 078b51a4 authored by tranoris's avatar tranoris
Browse files

Merge branch '4-extend-osom-for-patching-crs' into 'develop'

Resolve "Extend OSOM for patching CRs"

See merge request !3
parents d1499629 ebcfe156
No related branches found
No related tags found
2 merge requests!12Merging 2024Q2_RC into main, creating 2024Q2 Release,!3Resolve "Extend OSOM for patching CRs"
......@@ -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
*/
......
......@@ -1024,7 +1024,36 @@ public class ServiceOrderManager {
return null;
}
/**
* @param rFS_CRSPEC
* @param serviceId
*
*/
public String cridgeDeploymentUpdateRequest(Map<String, Object> 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;
}
/**
......
......@@ -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<Characteristic> 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<String, Object> 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 "";
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment