* ============LICENSE_START=======================================================
* ONAP CLAMP
* ================================================================================
- * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights
+ * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights
* reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
import com.google.gson.reflect.TypeToken;
import java.io.IOException;
import java.lang.reflect.Type;
-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.NotAuthorizedException;
import javax.xml.transform.TransformerException;
import org.apache.camel.Produce;
-import org.apache.commons.codec.DecoderException;
-import org.apache.commons.lang3.StringUtils;
import org.json.simple.parser.ParseException;
import org.onap.clamp.clds.camel.CamelProxy;
import org.onap.clamp.clds.client.DcaeDispatcherServices;
import org.onap.clamp.clds.client.DcaeInventoryServices;
-import org.onap.clamp.clds.client.req.sdc.SdcCatalogServices;
import org.onap.clamp.clds.config.ClampProperties;
import org.onap.clamp.clds.dao.CldsDao;
import org.onap.clamp.clds.exception.policy.PolicyClientException;
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.CldsInfo;
import org.onap.clamp.clds.model.CldsModel;
import org.onap.clamp.clds.model.CldsModelProp;
import org.onap.clamp.clds.model.CldsMonitoringDetails;
-import org.onap.clamp.clds.model.CldsServiceData;
import org.onap.clamp.clds.model.CldsTemplate;
import org.onap.clamp.clds.model.DcaeEvent;
import org.onap.clamp.clds.model.ValueItem;
@Component
public class CldsService extends SecureServiceBase {
+ /**
+ * The constant LIST_OF_SDC_SERVICE_INFO_TYPE.
+ */
public static final Type LIST_OF_SDC_SERVICE_INFO_TYPE = new TypeToken<List<SdcServiceInfo>>() {
}.getType();
@Produce(uri = "direct:processSubmit")
private CamelProxy camelProxy;
+ /**
+ * The constant securityLogger.
+ */
protected static final EELFLogger securityLogger = EELFManager.getInstance().getSecurityLogger();
+ /**
+ * The constant logger.
+ */
protected static final EELFLogger logger = EELFManager.getInstance().getLogger(CldsService.class);
+ /**
+ * The constant GLOBAL_PROPERTIES_KEY.
+ */
public static final String GLOBAL_PROPERTIES_KEY = "files.globalProperties";
- private final String cldsPersmissionTypeCl;
private final String cldsPermissionTypeClManage;
private final String cldsPermissionTypeClEvent;
private final String cldsPermissionTypeFilterVf;
- private final String cldsPermissionTypeTemplate;
private final String cldsPermissionInstance;
+ /**
+ * The Permission read cl.
+ */
final SecureServicePermission permissionReadCl;
+ /**
+ * The Permission update cl.
+ */
final SecureServicePermission permissionUpdateCl;
+ /**
+ * The Permission read template.
+ */
final SecureServicePermission permissionReadTemplate;
+ /**
+ * The Permission update template.
+ */
final SecureServicePermission permissionUpdateTemplate;
+ /**
+ * The Permission read tosca.
+ */
final SecureServicePermission permissionReadTosca;
+ /**
+ * The Permission update tosca.
+ */
final SecureServicePermission permissionUpdateTosca;
private final CldsDao cldsDao;
private final XslTransformer cldsBpmnTransformer;
private final ClampProperties refProp;
- private final SdcCatalogServices sdcCatalogServices;
private final DcaeDispatcherServices dcaeDispatcherServices;
private final DcaeInventoryServices dcaeInventoryServices;
private LoggingUtils util = new LoggingUtils(logger);
@Autowired
private HttpServletRequest request;
+ /**
+ * Instantiates a new Clds service.
+ *
+ * @param cldsDao the clds dao
+ * @param cldsBpmnTransformer the clds bpmn transformer
+ * @param refProp the ref prop
+ * @param dcaeDispatcherServices the dcae dispatcher services
+ * @param dcaeInventoryServices the dcae inventory services
+ * @param cldsPersmissionTypeCl the clds persmission type cl
+ * @param cldsPermissionTypeClManage the clds permission type cl manage
+ * @param cldsPermissionTypeClEvent the clds permission type cl event
+ * @param cldsPermissionTypeFilterVf the clds permission type filter vf
+ * @param cldsPermissionTypeTemplate the clds permission type template
+ * @param cldsPermissionTypeTosca the clds permission type tosca
+ * @param cldsPermissionInstance the clds permission instance
+ */
@Autowired
public CldsService(CldsDao cldsDao, XslTransformer cldsBpmnTransformer, ClampProperties refProp,
- SdcCatalogServices sdcCatalogServices, DcaeDispatcherServices dcaeDispatcherServices,
+ DcaeDispatcherServices dcaeDispatcherServices,
DcaeInventoryServices dcaeInventoryServices,
- @Value("${clamp.config.security.permission.type.cl:permission-type-cl}") String cldsPersmissionTypeCl,
- @Value("${clamp.config.security.permission.type.cl.manage:permission-type-cl-manage}") String cldsPermissionTypeClManage,
- @Value("${clamp.config.security.permission.type.cl.event:permission-type-cl-event}") String cldsPermissionTypeClEvent,
- @Value("${clamp.config.security.permission.type.filter.vf:permission-type-filter-vf}") String cldsPermissionTypeFilterVf,
- @Value("${clamp.config.security.permission.type.template:permission-type-template}") String cldsPermissionTypeTemplate,
- @Value("${clamp.config.security.permission.type.tosca:permission-type-tosca}") String cldsPermissionTypeTosca,
- @Value("${clamp.config.security.permission.instance:dev}") String cldsPermissionInstance) {
+ @Value("${clamp.config.security.permission.type.cl:permission-type-cl}")
+ String cldsPersmissionTypeCl,
+ @Value("${clamp.config.security.permission.type.cl.manage:permission-type-cl-manage}")
+ String cldsPermissionTypeClManage,
+ @Value("${clamp.config.security.permission.type.cl.event:permission-type-cl-event}")
+ String cldsPermissionTypeClEvent,
+ @Value("${clamp.config.security.permission.type.filter.vf:permission-type-filter-vf}")
+ String cldsPermissionTypeFilterVf,
+ @Value("${clamp.config.security.permission.type.template:permission-type-template}")
+ String cldsPermissionTypeTemplate,
+ @Value("${clamp.config.security.permission.type.tosca:permission-type-tosca}")
+ String cldsPermissionTypeTosca,
+ @Value("${clamp.config.security.permission.instance:dev}")
+ String cldsPermissionInstance) {
this.cldsDao = cldsDao;
this.cldsBpmnTransformer = cldsBpmnTransformer;
this.refProp = refProp;
- this.sdcCatalogServices = sdcCatalogServices;
this.dcaeDispatcherServices = dcaeDispatcherServices;
this.dcaeInventoryServices = dcaeInventoryServices;
- this.cldsPersmissionTypeCl = cldsPersmissionTypeCl;
this.cldsPermissionTypeClManage = cldsPermissionTypeClManage;
this.cldsPermissionTypeClEvent = cldsPermissionTypeClEvent;
this.cldsPermissionTypeFilterVf = cldsPermissionTypeFilterVf;
- this.cldsPermissionTypeTemplate = cldsPermissionTypeTemplate;
this.cldsPermissionInstance = cldsPermissionInstance;
permissionReadCl = SecureServicePermission.create(cldsPersmissionTypeCl, cldsPermissionInstance, "read");
permissionUpdateCl = SecureServicePermission.create(cldsPersmissionTypeCl, cldsPermissionInstance, "update");
"update");
}
- /*
- * @return list of CLDS-Monitoring-Details: CLOSELOOP_NAME | Close loop name
+ /**
+ * Gets clds details.
+ * list of CLDS-Monitoring-Details: CLOSELOOP_NAME | Close loop name
* used in the CLDS application (prefix: ClosedLoop- + unique ClosedLoop ID)
* MODEL_NAME | Model Name in CLDS application SERVICE_TYPE_ID | TypeId returned
* from the DCAE application when the ClosedLoop is submitted
* generated when the ClosedLoop is deployed in DCAE. TEMPLATE_NAME | Template
* used to generate the ClosedLoop model. ACTION_CD | Current state of the
* ClosedLoop in CLDS application.
+ * @return the clds details
*/
public List<CldsMonitoringDetails> getCldsDetails() {
util.entering(request, "CldsService: GET model details");
Date startTime = new Date();
- List<CldsMonitoringDetails> cldsMonitoringDetailsList = cldsDao.getCLDSMonitoringDetails();
+ List<CldsMonitoringDetails> cldsMonitoringDetailsList = cldsDao.getCldsMonitoringDetails();
// audit log
LoggingUtils.setTimeContext(startTime, new Date());
auditLogger.info("GET cldsDetails completed");
return cldsMonitoringDetailsList;
}
- /*
+ /**
+ * Gets clds info.
* 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
+ * @return the clds info
*/
public CldsInfo getCldsInfo() {
util.entering(request, "CldsService: GET cldsInfo");
* This is subset of the json getModel. This is only expected to be used for
* testing purposes, not by the UI.
*
- * @param modelName
+ * @param modelName the model name
* @return bpmn xml text - content of bpmn given name
*/
public String getBpmnXml(String modelName) {
* This is subset of the json getModel. This is only expected to be used for
* testing purposes, not by the UI.
*
- * @param modelName
+ * @param modelName the model name
* @return image xml text - content of image given name
*/
public String getImageXml(String modelName) {
/**
* REST service that retrieves a CLDS model by name from the database.
*
- * @param modelName
+ * @param modelName the model name
* @return clds model - clds model for the given model name
*/
public CldsModel getModel(String modelName) {
/**
* REST service that saves a CLDS model by name in the database.
*
- * @param modelName
+ * @param modelName the model name
+ * @param cldsModel the clds model
+ * @return the clds model
*/
public CldsModel putModel(String modelName, CldsModel cldsModel) {
util.entering(request, "CldsService: PUT model");
/**
* REST service that saves and processes an action for a CLDS model by name.
*
- * @param action
- * @param modelName
- * @param test
- * @param model
- * @return
- * @throws TransformerException
- * In case of issues when doing the XSLT of the BPMN flow
- * @throws ParseException
- * In case of issues when parsing the JSON
- * @throws GeneralSecurityException
- * In case of issues when decrypting the password
- * @throws DecoderException
- * In case of issues with the Hex String decoding
+ * @param action the action
+ * @param modelName the model name
+ * @param test the test
+ * @param model the model
+ * @return response entity
+ * @throws TransformerException In case of issues when doing the XSLT of the BPMN flow
+ * @throws ParseException In case of issues when parsing the JSON
*/
public ResponseEntity<?> putModelAndProcessAction(String action, String modelName, String test, CldsModel model)
throws TransformerException, ParseException {
errorMessage = e.getMessage();
}
- if (!errorMessage.isEmpty()) {
+ if (null == errorMessage || (null != errorMessage && !errorMessage.isEmpty())) {
CldsEvent.insEvent(cldsDao, model.getControlName(), getUserId(), actionCd, CldsEvent.ACTION_STATE_ERROR,
null);
// Need a refresh as new events have been inserted
model = CldsModel.retrieve(cldsDao, modelName, false);
+ if (null == errorMessage) {
+ errorMessage = "No response from Policy";
+ }
model.setErrorMessageForUi(errorMessage);
util.exiting(HttpStatus.INTERNAL_SERVER_ERROR.toString(), "putModelAndProcessAction failed", Level.INFO,
ONAPLogConstants.ResponseStatus.ERROR);
/**
* REST service that accepts events for a model.
*
- * @param test
- * @param dcaeEvent
+ * @param test the test
+ * @param dcaeEvent the dcae event
+ * @return the string
*/
public String postDcaeEvent(String test, DcaeEvent dcaeEvent) {
util.entering(request, "CldsService: Post dcae event");
}
/**
- * REST service that retrieves sdc services
+ * REST service that retrieves total properties required by UI.
*
- * @throws GeneralSecurityException
- * In case of issue when decryting the SDC password
- * @throws DecoderException
- * In case of issues with the decoding of the Hex String
- */
- public String getSdcServices() throws GeneralSecurityException, DecoderException {
- util.entering(request, "CldsService: GET sdc services");
- Date startTime = new Date();
- String retStr;
- try {
- retStr = createUiServiceFormatJson(sdcCatalogServices.getSdcServicesInformation(null));
- } catch (IOException e) {
- logger.error("IOException during SDC communication", e);
- throw new SdcCommunicationException("IOException during SDC communication", e);
- }
- logger.info("value of sdcServices : {}", retStr);
- // audit log
- LoggingUtils.setTimeContext(startTime, new Date());
- auditLogger.info("GET sdc services completed");
- util.exiting("200", "Get sdc services success", Level.INFO, ONAPLogConstants.ResponseStatus.COMPLETED);
- return retStr;
- }
-
- /**
- * REST service that retrieves total properties required by UI
- *
- * @throws IOException
- * In case of issues
+ * @return the sdc properties
+ * @throws IOException In case of issues
*/
public String getSdcProperties() throws IOException {
return refProp.getJsonTemplate(GLOBAL_PROPERTIES_KEY).toString();
}
- /**
- * REST service that retrieves total properties by using invariantUUID based on
- * refresh and non refresh
- *
- * @throws GeneralSecurityException
- * In case of issues with the decryting the encrypted password
- * @throws DecoderException
- * In case of issues with the decoding of the Hex String
- * @throws IOException
- * In case of issue to convert CldsServiceCache to InputStream
- */
- public String getSdcPropertiesByServiceUUIDForRefresh(String serviceInvariantUUID, Boolean refresh)
- throws GeneralSecurityException, DecoderException, IOException {
- util.entering(request, "CldsService: GET sdc properties by uuid");
- Date startTime = new Date();
- CldsServiceData cldsServiceData = new CldsServiceData();
- cldsServiceData.setServiceInvariantUUID(serviceInvariantUUID);
- if (!Optional.ofNullable(refresh).orElse(false)) {
- cldsServiceData = cldsDao.getCldsServiceCache(serviceInvariantUUID);
- }
- if (sdcCatalogServices.isCldsSdcCacheDataExpired(cldsServiceData)) {
- cldsServiceData = sdcCatalogServices.getCldsServiceDataWithAlarmConditions(serviceInvariantUUID);
- cldsDao.setCldsServiceCache(new CldsDbServiceCache(cldsServiceData));
- }
- // filter out VFs the user is not authorized for
- cldsServiceData.filterVfs(this);
- // format retrieved data into properties json
- String sdcProperties = sdcCatalogServices.createPropertiesObjectByUUID(cldsServiceData);
- // audit log
- LoggingUtils.setTimeContext(startTime, new Date());
- auditLogger.info("GET sdc properties by uuid completed");
- util.exiting("200", "Get sdc properties by uuid success", Level.INFO,
- ONAPLogConstants.ResponseStatus.COMPLETED);
- return sdcProperties;
- }
/**
* Determine if the user is authorized for a particular VF by its invariant
* UUID.
*
- * @param vfInvariantUuid
- * @throws NotAuthorizedException
- * @return
+ * @param vfInvariantUuid the vf invariant uuid
+ * @return boolean or throws NotAuthorizedException
*/
public boolean isAuthorizedForVf(String vfInvariantUuid) {
if (cldsPermissionTypeFilterVf != null && !cldsPermissionTypeFilterVf.isEmpty()) {
* Determine if the user is authorized for a particular VF by its invariant
* UUID. If not authorized, then NotAuthorizedException is thrown.
*
- * @param model
+ * @param model The clds model
* @return
*/
private boolean isAuthorizedForVf(CldsModel model) {
}
}
- private String createUiServiceFormatJson(String responseStr) throws IOException {
- if (StringUtils.isBlank(responseStr)) {
- return "";
- }
- List<SdcServiceInfo> rawList = JsonUtils.GSON.fromJson(responseStr, LIST_OF_SDC_SERVICE_INFO_TYPE);
- JsonObject invariantIdServiceNode = new JsonObject();
- JsonObject serviceNode = new JsonObject();
- logger.info("value of cldsserviceiNfolist: {}", rawList);
- if (rawList != null && !rawList.isEmpty()) {
- List<SdcServiceInfo> cldsSdcServiceInfoList = sdcCatalogServices.removeDuplicateServices(rawList);
- for (SdcServiceInfo currCldsSdcServiceInfo : cldsSdcServiceInfoList) {
- if (currCldsSdcServiceInfo != null) {
- invariantIdServiceNode.addProperty(currCldsSdcServiceInfo.getInvariantUUID(),
- currCldsSdcServiceInfo.getName());
- }
- }
- serviceNode.add("service", invariantIdServiceNode);
- }
- return serviceNode.toString();
- }
-
+ /**
+ * Deploy model response entity.
+ *
+ * @param modelName the model name
+ * @param model the model
+ * @return the response entity
+ */
public ResponseEntity<CldsModel> deployModel(String modelName, CldsModel model) {
util.entering(request, "CldsService: Deploy model");
Date startTime = new Date();
}
}
+ /**
+ * Un deploy model response entity.
+ *
+ * @param modelName the model name
+ * @param model the model
+ * @return the response entity
+ */
public ResponseEntity<CldsModel> unDeployModel(String modelName, CldsModel model) {
util.entering(request, "CldsService: Undeploy model");
Date startTime = new Date();
}
}
+ /**
+ * Sets logging util.
+ *
+ * @param utilP the util p
+ */
// Created for the integration test
public void setLoggingUtil(LoggingUtils utilP) {
util = utilP;