import java.security.GeneralSecurityException;
import java.util.Date;
import java.util.List;
+import java.util.Optional;
import java.util.UUID;
+import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.BadRequestException;
-import javax.ws.rs.Consumes;
-import javax.ws.rs.DefaultValue;
-import javax.ws.rs.GET;
import javax.ws.rs.NotAuthorizedException;
-import javax.ws.rs.POST;
-import javax.ws.rs.PUT;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-import javax.ws.rs.QueryParam;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
import javax.xml.transform.TransformerException;
import org.apache.camel.Produce;
import org.onap.clamp.clds.exception.sdc.SdcCommunicationException;
import org.onap.clamp.clds.model.CldsDbServiceCache;
import org.onap.clamp.clds.model.CldsEvent;
-import org.onap.clamp.clds.model.CldsHealthCheck;
import org.onap.clamp.clds.model.CldsInfo;
import org.onap.clamp.clds.model.CldsModel;
import org.onap.clamp.clds.model.CldsModelProp;
import org.onap.clamp.clds.transform.XslTransformer;
import org.onap.clamp.clds.util.JacksonUtils;
import org.onap.clamp.clds.util.LoggingUtils;
+import org.onap.clamp.clds.util.ONAPLogConstants;
+import org.slf4j.event.Level;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.web.client.HttpClientErrorException;
* Service to save and retrieve the CLDS model attributes.
*/
@Component
-@Path("/clds")
public class CldsService extends SecureServiceBase {
@Produce(uri = "direct:processSubmit")
private CamelProxy camelProxy;
protected static final EELFLogger securityLogger = EELFManager.getInstance().getSecurityLogger();
- static final String RESOURCE_NAME = "clds-version.properties";
+ protected static final EELFLogger logger = EELFManager.getInstance().getLogger(CldsService.class);
+
public static final String GLOBAL_PROPERTIES_KEY = "files.globalProperties";
private final String cldsPersmissionTypeCl;
private final String cldsPermissionTypeClManage;
private final SdcCatalogServices sdcCatalogServices;
private final DcaeDispatcherServices dcaeDispatcherServices;
private final DcaeInventoryServices dcaeInventoryServices;
+ private LoggingUtils util = new LoggingUtils(logger);
+ @Autowired
+ private HttpServletRequest request;
@Autowired
public CldsService(CldsDao cldsDao, XslTransformer cldsBpmnTransformer, ClampProperties refProp,
SdcCatalogServices sdcCatalogServices, DcaeDispatcherServices dcaeDispatcherServices,
* used to generate the ClosedLoop model. ACTION_CD | Current state of the
* ClosedLoop in CLDS application.
*/
- @GET
- @Path("/cldsDetails")
- @Produces(MediaType.APPLICATION_JSON)
public List<CldsMonitoringDetails> getCLDSDetails() {
+ util.entering(request, "CldsService: GET model details");
Date startTime = new Date();
- LoggingUtils.setRequestContext("CldsService: GET model details", getPrincipalName());
List<CldsMonitoringDetails> cldsMonitoringDetailsList = cldsDao.getCLDSMonitoringDetails();
// audit log
LoggingUtils.setTimeContext(startTime, new Date());
- LoggingUtils.setResponseContext("0", "Get cldsDetails success", this.getClass().getName());
auditLogger.info("GET cldsDetails completed");
+ util.exiting("200", "Get cldsDetails success", Level.INFO, ONAPLogConstants.ResponseStatus.COMPLETED);
return cldsMonitoringDetailsList;
}
* CLDS IFO service will return 3 things 1. User Name 2. CLDS code version that
* is currently installed from pom.xml file 3. User permissions
*/
- @GET
- @Path("/cldsInfo")
- @Produces(MediaType.APPLICATION_JSON)
public CldsInfo getCldsInfo() {
+ util.entering(request, "CldsService: GET cldsInfo");
Date startTime = new Date();
- LoggingUtils.setRequestContext("CldsService: GET cldsInfo", getPrincipalName());
LoggingUtils.setTimeContext(startTime, new Date());
CldsInfoProvider cldsInfoProvider = new CldsInfoProvider(this);
// audit log
LoggingUtils.setTimeContext(startTime, new Date());
- LoggingUtils.setResponseContext("0", "Get cldsInfo success", this.getClass().getName());
securityLogger.info("GET cldsInfo completed");
+ util.exiting("200", "Get cldsInfo success", Level.INFO, ONAPLogConstants.ResponseStatus.COMPLETED);
return cldsInfo;
}
- /**
- * REST service that retrieves clds healthcheck information.
- *
- * @return CldsHealthCheck class containing healthcheck info
- */
- @GET
- @Path("/healthcheck")
- @Produces(MediaType.APPLICATION_JSON)
- public Response gethealthcheck() {
- CldsHealthCheck cldsHealthCheck = new CldsHealthCheck();
- Date startTime = new Date();
- 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());
- 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();
- }
- }
-
/**
* REST service that retrieves BPMN for a CLDS model name from the database.
* This is subset of the json getModel. This is only expected to be used for
* @param modelName
* @return bpmn xml text - content of bpmn given name
*/
- @GET
- @Path("/model/bpmn/{modelName}")
- @Produces(MediaType.TEXT_XML)
- public String getBpmnXml(@PathParam("modelName") String modelName) {
+ public String getBpmnXml(String modelName) {
+ util.entering(request, "CldsService: GET model bpmn");
Date startTime = new Date();
- LoggingUtils.setRequestContext("CldsService: GET model bpmn", getPrincipalName());
isAuthorized(permissionReadCl);
logger.info("GET bpmnText for modelName={}", modelName);
CldsModel model = CldsModel.retrieve(cldsDao, modelName, false);
// audit log
LoggingUtils.setTimeContext(startTime, new Date());
- LoggingUtils.setResponseContext("0", "Get model bpmn success", this.getClass().getName());
auditLogger.info("GET model bpmn completed");
+ util.exiting("200", "Get model bpmn success", Level.INFO, ONAPLogConstants.ResponseStatus.COMPLETED);
return model.getBpmnText();
}
* @param modelName
* @return image xml text - content of image given name
*/
- @GET
- @Path("/model/image/{modelName}")
- @Produces(MediaType.TEXT_XML)
- public String getImageXml(@PathParam("modelName") String modelName) {
+ public String getImageXml(String modelName) {
+ util.entering(request, "CldsService: GET model image");
Date startTime = new Date();
- LoggingUtils.setRequestContext("CldsService: GET model image", getPrincipalName());
isAuthorized(permissionReadCl);
logger.info("GET imageText for modelName={}", modelName);
CldsModel model = CldsModel.retrieve(cldsDao, modelName, false);
// audit log
LoggingUtils.setTimeContext(startTime, new Date());
- LoggingUtils.setResponseContext("0", "Get model image success", this.getClass().getName());
auditLogger.info("GET model image completed");
+ util.exiting("200", "Get model image success", Level.INFO, ONAPLogConstants.ResponseStatus.COMPLETED);
return model.getImageText();
}
* @param modelName
* @return clds model - clds model for the given model name
*/
- @GET
- @Path("/model/{modelName}")
- @Produces(MediaType.APPLICATION_JSON)
- public CldsModel getModel(@PathParam("modelName") String modelName) {
+ public CldsModel getModel(String modelName) {
+ util.entering(request, "CldsService: GET model");
Date startTime = new Date();
- LoggingUtils.setRequestContext("CldsService: GET model", getPrincipalName());
isAuthorized(permissionReadCl);
logger.debug("GET model for modelName={}", modelName);
CldsModel cldsModel = CldsModel.retrieve(cldsDao, modelName, false);
}
// audit log
LoggingUtils.setTimeContext(startTime, new Date());
- LoggingUtils.setResponseContext("0", "Get model success", this.getClass().getName());
auditLogger.info("GET model completed");
+ util.exiting("200", "Get model success", Level.INFO, ONAPLogConstants.ResponseStatus.COMPLETED);
return cldsModel;
}
*
* @param modelName
*/
- @PUT
- @Path("/model/{modelName}")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- public CldsModel putModel(@PathParam("modelName") String modelName, CldsModel cldsModel) {
+ public CldsModel putModel(String modelName, CldsModel cldsModel) {
+ util.entering(request, "CldsService: PUT model");
Date startTime = new Date();
- LoggingUtils.setRequestContext("CldsService: PUT model", getPrincipalName());
isAuthorized(permissionUpdateCl);
isAuthorizedForVf(cldsModel);
logger.info("PUT model for modelName={}", modelName);
cldsModel.save(cldsDao, getUserId());
// audit log
LoggingUtils.setTimeContext(startTime, new Date());
- LoggingUtils.setResponseContext("0", "Put model success", this.getClass().getName());
auditLogger.info("PUT model completed");
+ util.exiting("200", "Put model success", Level.INFO, ONAPLogConstants.ResponseStatus.COMPLETED);
return cldsModel;
}
*
* @return model names in JSON
*/
- @GET
- @Path("/model-names")
- @Produces(MediaType.APPLICATION_JSON)
public List<ValueItem> getModelNames() {
+ util.entering(request, "CldsService: GET model names");
Date startTime = new Date();
- LoggingUtils.setRequestContext("CldsService: GET model names", getPrincipalName());
isAuthorized(permissionReadCl);
logger.info("GET list of model names");
List<ValueItem> names = cldsDao.getBpmnNames();
// audit log
LoggingUtils.setTimeContext(startTime, new Date());
- LoggingUtils.setResponseContext("0", "Get model names success", this.getClass().getName());
auditLogger.info("GET model names completed");
+ util.exiting("200", "Get model names success", Level.INFO, ONAPLogConstants.ResponseStatus.COMPLETED);
return names;
}
* @throws DecoderException
* In case of issues with the Hex String decoding
*/
- @PUT
- @Path("/action/{action}/{modelName}")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- public Response putModelAndProcessAction(@PathParam("action") String action,
- @PathParam("modelName") String modelName, @QueryParam("test") String validateFlag, CldsModel model)
+ public ResponseEntity<?> putModelAndProcessAction(String action,
+ String modelName,String test, CldsModel model)
throws TransformerException, ParseException {
+ util.entering(request, "CldsService: Process model action");
Date startTime = new Date();
CldsModel retrievedModel = null;
Boolean errorCase = false;
try {
- LoggingUtils.setRequestContext("CldsService: Process model action", getPrincipalName());
String actionCd = action.toUpperCase();
SecureServicePermission permisionManage = SecureServicePermission.create(cldsPermissionTypeClManage,
cldsPermissionInstance, actionCd);
String userId = getUserId();
logger.info("PUT actionCd={}", actionCd);
logger.info("PUT modelName={}", modelName);
- logger.info("PUT test={}", validateFlag);
+ logger.info("PUT test={}", test);
logger.info("PUT bpmnText={}", model.getBpmnText());
logger.info("PUT propText={}", model.getPropText());
logger.info("PUT userId={}", userId);
// Flag indicates whether it is triggered by Validation Test button
// from
// UI
- boolean isTest = Boolean.valueOf(validateFlag);
+ boolean isTest = Boolean.valueOf(test);
if (!isTest) {
String actionTestOverride = refProp.getStringValue("action.test.override");
if (Boolean.valueOf(actionTestOverride)) {
}
// audit log
LoggingUtils.setTimeContext(startTime, new Date());
- LoggingUtils.setResponseContext("0", "Process model action success", this.getClass().getName());
auditLogger.info("Process model action completed");
} else {
logger.error("CldsModel not found in database with modelName: " + modelName);
- return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity("CldsModel not found in database with modelName: \" + modelName").build();
+ util.exiting(HttpStatus.INTERNAL_SERVER_ERROR.toString(), "CldsModel not found in database with modelName " + "modelName", Level.INFO, ONAPLogConstants.ResponseStatus.ERROR);
+ return new ResponseEntity<String>("CldsModel not found in database with modelName: \" + modelName", HttpStatus.INTERNAL_SERVER_ERROR);
}
} catch (Exception e) {
errorCase = true;
logger.error("Exception occured during putModelAndProcessAction", e);
}
if (errorCase) {
- return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(retrievedModel).build();
+ util.exiting(HttpStatus.INTERNAL_SERVER_ERROR.toString(), "putModelAndProcessAction failed", Level.INFO, ONAPLogConstants.ResponseStatus.ERROR);
+ return new ResponseEntity<>(retrievedModel, HttpStatus.INTERNAL_SERVER_ERROR);
}
- return Response.status(Response.Status.OK).entity(retrievedModel).build();
+ util.exiting(HttpStatus.OK.toString(), "Successful", Level.INFO, ONAPLogConstants.ResponseStatus.COMPLETED);
+ return new ResponseEntity<>(retrievedModel, HttpStatus.OK);
}
/**
* @param test
* @param dcaeEvent
*/
- @POST
- @Path("/dcae/event")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- public String postDcaeEvent(@QueryParam("test") String test, DcaeEvent dcaeEvent) {
+ public String postDcaeEvent(String test, DcaeEvent dcaeEvent) {
+ util.entering(request, "CldsService: Post dcae event");
Date startTime = new Date();
- LoggingUtils.setRequestContext("CldsService: Post dcae event", getPrincipalName());
String userid = null;
// TODO: allow auth checking to be turned off by removing the permission
// type property
}
// audit log
LoggingUtils.setTimeContext(startTime, new Date());
- LoggingUtils.setResponseContext("0", "Post dcae event success", this.getClass().getName());
auditLogger.info("Post dcae event completed");
+ util.exiting("200", "Post dcae event success", Level.INFO, ONAPLogConstants.ResponseStatus.COMPLETED);
return msgInfo;
}
* @throws DecoderException
* In case of issues with the decoding of the Hex String
*/
- @GET
- @Path("/sdc/services")
- @Produces(MediaType.APPLICATION_JSON)
public String getSdcServices() throws GeneralSecurityException, DecoderException {
+ util.entering(request, "CldsService: GET sdc services");
Date startTime = new Date();
- LoggingUtils.setRequestContext("CldsService: GET sdc services", getPrincipalName());
String retStr;
try {
retStr = createUiServiceFormatJson(sdcCatalogServices.getSdcServicesInformation(null));
logger.info("value of sdcServices : {}", retStr);
// audit log
LoggingUtils.setTimeContext(startTime, new Date());
- LoggingUtils.setResponseContext("0", "Get sdc services success", this.getClass().getName());
auditLogger.info("GET sdc services completed");
+ util.exiting("200", "Get sdc services success", Level.INFO, ONAPLogConstants.ResponseStatus.COMPLETED);
return retStr;
}
* @throws IOException
* In case of issues
*/
- @GET
- @Path("/properties")
- @Produces(MediaType.APPLICATION_JSON)
public String getSdcProperties() throws IOException {
return createPropertiesObjectByUUID("{}");
}
* @throws IOException
* In case of issue to convert CldsServiceCache to InputStream
*/
- @GET
- @Path("/properties/{serviceInvariantUUID}")
- @Produces(MediaType.APPLICATION_JSON)
public String getSdcPropertiesByServiceUUIDForRefresh(
- @PathParam("serviceInvariantUUID") String serviceInvariantUUID,
- @DefaultValue("false") @QueryParam("refresh") boolean refresh)
+ String serviceInvariantUUID, Boolean refresh)
throws GeneralSecurityException, DecoderException, IOException {
+ util.entering(request, "CldsService: GET sdc properties by uuid");
Date startTime = new Date();
- LoggingUtils.setRequestContext("CldsService: GET sdc properties by uuid", getPrincipalName());
CldsServiceData cldsServiceData = new CldsServiceData();
cldsServiceData.setServiceInvariantUUID(serviceInvariantUUID);
- if (!refresh) {
+ if (!Optional.ofNullable(refresh).orElse(false)) {
cldsServiceData = cldsDao.getCldsServiceCache(serviceInvariantUUID);
}
if (sdcCatalogServices.isCldsSdcCacheDataExpired(cldsServiceData)) {
String sdcProperties = sdcCatalogServices.createPropertiesObjectByUUID(cldsServiceData);
// audit log
LoggingUtils.setTimeContext(startTime, new Date());
- LoggingUtils.setResponseContext("0", "Get sdc properties by uuid success", this.getClass().getName());
auditLogger.info("GET sdc properties by uuid completed");
+ util.exiting("200", "Get sdc properties by uuid success", Level.INFO, ONAPLogConstants.ResponseStatus.COMPLETED);
return sdcProperties;
}
return emptyvfcobjectNode;
}
- @PUT
- @Path("/deploy/{modelName}")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- public Response deployModel(@PathParam("modelName") String modelName, CldsModel model) {
+ public ResponseEntity<CldsModel> deployModel(String modelName, CldsModel model) {
+ util.entering(request, "CldsService: Deploy model");
Date startTime = new Date();
- LoggingUtils.setRequestContext("CldsService: Deploy model", getPrincipalName());
Boolean errorCase = false;
try {
fillInCldsModel(model);
model.save(cldsDao, getUserId());
} else {
logger.info("Deploy model (" + modelName + ") failed...Operation Status is - " + operationStatus);
+ util.exiting(HttpStatus.INTERNAL_SERVER_ERROR.toString(), "DeployModel failed", Level.INFO, ONAPLogConstants.ResponseStatus.ERROR);
throw new HttpClientErrorException(HttpStatus.INTERNAL_SERVER_ERROR,
"Deploy model (" + modelName + ") failed...Operation Status is - " + operationStatus);
}
logger.info("Deploy model (" + modelName + ") succeeded...Deployment Id is - " + deploymentId);
// audit log
LoggingUtils.setTimeContext(startTime, new Date());
- LoggingUtils.setResponseContext("0", "Deploy model success", this.getClass().getName());
auditLogger.info("Deploy model completed");
} catch (Exception e) {
errorCase = true;
logger.error("Exception occured during deployModel", e);
}
if (errorCase) {
- return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(model).build();
+ util.exiting(HttpStatus.INTERNAL_SERVER_ERROR.toString(), "DeployModel failed", Level.INFO, ONAPLogConstants.ResponseStatus.ERROR);
+ return new ResponseEntity<>(model, HttpStatus.INTERNAL_SERVER_ERROR);
}
- return Response.status(Response.Status.OK).entity(model).build();
+ util.exiting(HttpStatus.OK.toString(), "Successful", Level.INFO, ONAPLogConstants.ResponseStatus.COMPLETED);
+ return new ResponseEntity<>(model, HttpStatus.OK);
}
- @PUT
- @Path("/undeploy/{modelName}")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- public Response unDeployModel(@PathParam("modelName") String modelName, CldsModel model) {
+ public ResponseEntity<CldsModel> unDeployModel(String modelName, CldsModel model) {
+ util.entering(request, "CldsService: Undeploy model");
Date startTime = new Date();
- LoggingUtils.setRequestContext("CldsService: Undeploy model", getPrincipalName());
Boolean errorCase = false;
try {
SecureServicePermission permisionManage = SecureServicePermission.create(cldsPermissionTypeClManage,
model.save(cldsDao, getUserId());
} else {
logger.info("Undeploy model (" + modelName + ") failed...Operation Status is - " + operationStatus);
+ util.exiting(HttpStatus.INTERNAL_SERVER_ERROR.toString(), "UndeployModel failed", Level.INFO, ONAPLogConstants.ResponseStatus.ERROR);
throw new HttpClientErrorException(HttpStatus.INTERNAL_SERVER_ERROR,
"Undeploy model (" + modelName + ") failed...Operation Status is - " + operationStatus);
}
logger.info("Undeploy model (" + modelName + ") succeeded.");
// audit log
LoggingUtils.setTimeContext(startTime, new Date());
- LoggingUtils.setResponseContext("0", "Undeploy model success", this.getClass().getName());
auditLogger.info("Undeploy model completed");
} catch (Exception e) {
errorCase = true;
logger.error("Exception occured during unDeployModel", e);
}
if (errorCase) {
- return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(model).build();
+ util.exiting(HttpStatus.INTERNAL_SERVER_ERROR.toString(), "UndeployModel failed", Level.INFO, ONAPLogConstants.ResponseStatus.ERROR);
+ return new ResponseEntity<>(model, HttpStatus.INTERNAL_SERVER_ERROR);
}
- return Response.status(Response.Status.OK).entity(model).build();
+ util.exiting(HttpStatus.OK.toString(), "Successful", Level.INFO, ONAPLogConstants.ResponseStatus.COMPLETED);
+ return new ResponseEntity<>(model, HttpStatus.OK);
}
private void checkForDuplicateServiceVf(String modelName, String modelPropText) throws IOException {
cldsDao.insEvent(cldsModelName, cldsControlNamePrfx, null, newEvent);
}
}
+
+ // Created for the integration test
+ public void setLoggingUtil (LoggingUtils utilP) {
+ util = utilP;
+ }
}
\ No newline at end of file