* limitations under the License.
* ============LICENSE_END============================================
* ===================================================================
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ *
*/
package org.onap.clamp.clds.service;
import java.io.IOException;
import java.io.InputStream;
import java.security.GeneralSecurityException;
-import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Properties;
import java.util.UUID;
-import java.util.concurrent.TimeUnit;
import javax.annotation.PostConstruct;
import javax.ws.rs.BadRequestException;
import org.onap.clamp.clds.model.sdc.SdcResource;
import org.onap.clamp.clds.model.sdc.SdcServiceDetail;
import org.onap.clamp.clds.model.sdc.SdcServiceInfo;
+import org.onap.clamp.clds.sdc.controller.installer.CsarInstallerImpl;
import org.onap.clamp.clds.transform.XslTransformer;
import org.onap.clamp.clds.util.JacksonUtils;
import org.onap.clamp.clds.util.LoggingUtils;
public List<CldsMonitoringDetails> getCLDSDetails() {
Date startTime = new Date();
LoggingUtils.setRequestContext("CldsService: GET model details", getPrincipalName());
- List<CldsMonitoringDetails> cldsMonitoringDetailsList = new ArrayList<CldsMonitoringDetails>();
- cldsMonitoringDetailsList = cldsDao.getCLDSMonitoringDetails();
+ List<CldsMonitoringDetails> cldsMonitoringDetailsList = cldsDao.getCLDSMonitoringDetails();
// audit log
LoggingUtils.setTimeContext(startTime, new Date());
LoggingUtils.setResponseContext("0", "Get cldsDetails success", this.getClass().getName());
@GET
@Path("/healthcheck")
@Produces(MediaType.APPLICATION_JSON)
- public CldsHealthCheck gethealthcheck() {
+ public Response gethealthcheck() {
CldsHealthCheck cldsHealthCheck = new CldsHealthCheck();
Date startTime = new Date();
- LoggingUtils.setRequestContext("CldsService: GET healthcheck", getPrincipalName());
+ LoggingUtils.setRequestContext("CldsService: GET healthcheck", "Clamp-Health-Check");
LoggingUtils.setTimeContext(startTime, new Date());
+ boolean healthcheckFailed = false;
try {
cldsDao.doHealthCheck();
cldsHealthCheck.setHealthCheckComponent("CLDS-APP");
cldsHealthCheck.setHealthCheckStatus("UP");
cldsHealthCheck.setDescription("OK");
+ LoggingUtils.setResponseContext("0", "Get healthcheck success", this.getClass().getName());
} catch (Exception e) {
+ healthcheckFailed = true;
logger.error("CLAMP application DB Error", e);
+ LoggingUtils.setResponseContext("999", "Get healthcheck failed", this.getClass().getName());
cldsHealthCheck.setHealthCheckComponent("CLDS-APP");
cldsHealthCheck.setHealthCheckStatus("DOWN");
cldsHealthCheck.setDescription("NOT-OK");
}
// audit log
LoggingUtils.setTimeContext(startTime, new Date());
- LoggingUtils.setResponseContext("0", "Get healthcheck success", this.getClass().getName());
- securityLogger.info("GET healthcheck completed");
- return cldsHealthCheck;
+ logger.info("GET healthcheck completed");
+ if (healthcheckFailed) {
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(cldsHealthCheck).build();
+ } else {
+ return Response.status(Response.Status.OK).entity(cldsHealthCheck).build();
+ }
}
/**
cldsModel.setBpmnText(template.getBpmnText());
}
}
+ updateAndInsertNewEvent(cldsModel.getName(), cldsModel.getControlNamePrefix(), cldsModel.getEvent(),
+ CldsEvent.ACTION_MODIFY);
cldsModel.save(cldsDao, getUserId());
// audit log
LoggingUtils.setTimeContext(startTime, new Date());
this.fillInCldsModel(model);
// save model to db
model.setName(modelName);
+ updateAndInsertNewEvent(modelName, model.getControlNamePrefix(), model.getEvent(), CldsEvent.ACTION_MODIFY);
model.save(cldsDao, getUserId());
// get vars and format if necessary
String prop = model.getPropText();
logger.info("docText - " + docText);
try {
String result = camelProxy.submit(actionCd, prop, bpmnJson, modelName, controlName, docText, isTest,
- userId, isInsertTestEvent);
+ userId, isInsertTestEvent, model.getEvent().getActionCd());
logger.info("Starting Camel flow on request, result is: ", result);
} catch (SdcCommunicationException | PolicyClientException | BadRequestException e) {
errorCase = true;
logger.error("Exception occured during invoking Camel process", e);
}
- // refresh model info from db (get fresh event info)
- retrievedModel = CldsModel.retrieve(cldsDao, modelName, false);
+ if (!actionCd.equalsIgnoreCase(CldsEvent.ACTION_DELETE)) {
+ // refresh model info from db (get fresh event info)
+ retrievedModel = CldsModel.retrieve(cldsDao, modelName, false);
+ }
if (!isTest && (actionCd.equalsIgnoreCase(CldsEvent.ACTION_SUBMIT)
|| actionCd.equalsIgnoreCase(CldsEvent.ACTION_RESUBMIT)
|| actionCd.equalsIgnoreCase(CldsEvent.ACTION_SUBMITDCAE))) {
- // To verify inventory status and modify model status to
- // distribute
- dcaeInventoryServices.setEventInventory(retrievedModel, getUserId());
+ if (retrievedModel.getTemplateName().startsWith(CsarInstallerImpl.TEMPLATE_NAME_PREFIX)) {
+ // SDC artifact case
+ logger.info("Skipping DCAE inventory call as closed loop has been created from SDC notification");
+ DcaeEvent dcaeEvent = new DcaeEvent();
+ dcaeEvent.setArtifactName(retrievedModel.getControlName() + ".yml");
+ dcaeEvent.setEvent(DcaeEvent.EVENT_DISTRIBUTION);
+ CldsEvent.insEvent(cldsDao, dcaeEvent.getControlName(), userId, dcaeEvent.getCldsActionCd(),
+ CldsEvent.ACTION_STATE_RECEIVED, null);
+ } else {
+ // This should be done only when the call to DCAE
+ // has not yet been done. When CL comes from SDC
+ // this is not required as the DCAE inventory call is done
+ // during the CL deployment.
+ dcaeInventoryServices.setEventInventory(retrievedModel, getUserId());
+ }
retrievedModel.save(cldsDao, getUserId());
}
// audit log
fillInCldsModel(model);
String bpmnJson = cldsBpmnTransformer.doXslTransformToString(model.getBpmnText());
logger.info("PUT bpmnJson={}", bpmnJson);
+ SecureServicePermission permisionManage = SecureServicePermission.create(cldsPermissionTypeClManage,
+ cldsPermissionInstance, CldsEvent.ACTION_DEPLOY);
+ isAuthorized(permisionManage);
+ isAuthorizedForVf(model);
ModelProperties modelProp = new ModelProperties(modelName, model.getControlName(), CldsEvent.ACTION_DEPLOY,
false, bpmnJson, model.getPropText());
checkForDuplicateServiceVf(modelName, model.getPropText());
}
String createNewDeploymentStatusUrl = dcaeDispatcherServices.createNewDeployment(deploymentId,
model.getTypeId(), modelProp.getGlobal().getDeployParameters());
- String operationStatus = "processing";
- long waitingTime = System.nanoTime() + TimeUnit.MINUTES.toNanos(10);
- while ("processing".equalsIgnoreCase(operationStatus)) {
- // Break the loop if waiting for more than 10 mins
- if (waitingTime < System.nanoTime()) {
- break;
- }
- operationStatus = dcaeDispatcherServices.getOperationStatus(createNewDeploymentStatusUrl);
- }
+ String operationStatus = dcaeDispatcherServices.getOperationStatusWithRetry(createNewDeploymentStatusUrl);
if ("succeeded".equalsIgnoreCase(operationStatus)) {
String artifactName = model.getControlName();
if (artifactName != null) {
LoggingUtils.setRequestContext("CldsService: Undeploy model", getPrincipalName());
Boolean errorCase = false;
try {
+ SecureServicePermission permisionManage = SecureServicePermission.create(cldsPermissionTypeClManage,
+ cldsPermissionInstance, CldsEvent.ACTION_UNDEPLOY);
+ isAuthorized(permisionManage);
+ isAuthorizedForVf(model);
String operationStatusUndeployUrl = dcaeDispatcherServices.deleteExistingDeployment(model.getDeploymentId(),
model.getTypeId());
- String operationStatus = "processing";
- long waitingTime = System.nanoTime() + TimeUnit.MINUTES.toNanos(10);
- while ("processing".equalsIgnoreCase(operationStatus)) {
- if (waitingTime < System.nanoTime()) {
- break;
- }
- operationStatus = dcaeDispatcherServices.getOperationStatus(operationStatusUndeployUrl);
- }
+ String operationStatus = dcaeDispatcherServices.getOperationStatusWithRetry(operationStatusUndeployUrl);
if ("succeeded".equalsIgnoreCase(operationStatus)) {
String artifactName = model.getControlName();
if (artifactName != null) {
}
}
}
+
+ private void updateAndInsertNewEvent(String cldsModelName, String cldsControlNamePrfx, CldsEvent event,
+ String newAction) {
+ // If model action is in submit/resubmit/distributed and user try
+ // to save then we are changing action back to create.
+ if (event != null && (CldsEvent.ACTION_SUBMIT.equalsIgnoreCase(event.getActionCd())
+ || CldsEvent.ACTION_RESUBMIT.equalsIgnoreCase(event.getActionCd())
+ || CldsEvent.ACTION_DISTRIBUTE.equalsIgnoreCase(event.getActionCd()))) {
+ CldsEvent newEvent = new CldsEvent();
+ newEvent.setUserid(getUserId());
+ newEvent.setActionCd(newAction);
+ newEvent.setActionStateCd(CldsEvent.ACTION_STATE_COMPLETED);
+ cldsDao.insEvent(cldsModelName, cldsControlNamePrfx, null, newEvent);
+ }
+ }
}
\ No newline at end of file