aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/org/onap/clamp/clds/client/SdcSendReqDelegate.java60
-rw-r--r--src/main/java/org/onap/clamp/clds/exception/DcaeDeploymentException.java61
-rw-r--r--src/main/java/org/onap/clamp/clds/service/CldsService.java76
-rw-r--r--src/main/java/org/onap/clamp/clds/service/SecureServiceBase.java29
4 files changed, 127 insertions, 99 deletions
diff --git a/src/main/java/org/onap/clamp/clds/client/SdcSendReqDelegate.java b/src/main/java/org/onap/clamp/clds/client/SdcSendReqDelegate.java
index 47a4ddc87..ee233686b 100644
--- a/src/main/java/org/onap/clamp/clds/client/SdcSendReqDelegate.java
+++ b/src/main/java/org/onap/clamp/clds/client/SdcSendReqDelegate.java
@@ -28,9 +28,7 @@ import java.util.List;
import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.camunda.bpm.engine.delegate.JavaDelegate;
import org.onap.clamp.clds.client.req.SdcReq;
-import org.onap.clamp.clds.model.CldsSdcServiceDetail;
import org.onap.clamp.clds.model.DcaeEvent;
-import org.onap.clamp.clds.model.prop.Global;
import org.onap.clamp.clds.model.prop.ModelProperties;
import org.onap.clamp.clds.model.refprop.RefProp;
import org.springframework.beans.factory.annotation.Autowired;
@@ -85,62 +83,14 @@ public class SdcSendReqDelegate implements JavaDelegate {
if (formattedSdcLocationReq != null) {
execution.setVariable("formattedLocationReq", formattedSdcLocationReq.getBytes());
}
- String serviceInvariantUUID = getServiceInvariantUUIDFromProps(prop);
- uploadToSdc(prop, serviceInvariantUUID, userid, sdcReqUrlsList, formatttedSdcReq, formattedSdcLocationReq,
+ sdcCatalogServices.uploadToSdc(prop, userid, sdcReqUrlsList, formatttedSdcReq, formattedSdcLocationReq,
artifactName, locationArtifactName);
}
- private String getServiceInvariantUUIDFromProps(ModelProperties props) {
- String invariantUUID = "";
- Global globalProps = props.getGlobal();
- if (globalProps != null) {
- if (globalProps.getService() != null) {
- invariantUUID = globalProps.getService();
- }
- }
- return invariantUUID;
- }
-
- private void uploadToSdc(ModelProperties prop, String serviceInvariantUUID, String userid,
- List<String> sdcReqUrlsList, String formatttedSdcReq, String formattedSdcLocationReq, String artifactName,
- String locationArtifactName) throws Exception {
- logger.info("userid=" + userid);
- if (sdcReqUrlsList != null && sdcReqUrlsList.size() > 0) {
- for (String url : sdcReqUrlsList) {
- if (url != null) {
- String originalServiceUUID = sdcCatalogServices
- .getServiceUuidFromServiceInvariantId(serviceInvariantUUID);
- logger.info("ServiceUUID used before upload in url:" + originalServiceUUID);
- String sdcServicesInformation = sdcCatalogServices.getSdcServicesInformation(originalServiceUUID);
- CldsSdcServiceDetail CldsSdcServiceDetail = sdcCatalogServices
- .getCldsSdcServiceDetailFromJson(sdcServicesInformation);
- String uploadedArtifactUUID = sdcCatalogServices
- .getArtifactIdIfArtifactAlreadyExists(CldsSdcServiceDetail, artifactName);
- // Upload artifacts to sdc
- String updateUrl = uploadedArtifactUUID != null ? url + "/" + uploadedArtifactUUID : url;
- String responseStr = sdcCatalogServices.uploadArtifactToSdc(prop, userid, updateUrl,
- formatttedSdcReq);
- logger.info("value of sdc Response of uploading to sdc :" + responseStr);
- String updatedServiceUUID = sdcCatalogServices
- .getServiceUuidFromServiceInvariantId(serviceInvariantUUID);
- if (!originalServiceUUID.equalsIgnoreCase(updatedServiceUUID)) {
- url = url.replace(originalServiceUUID, updatedServiceUUID);
- }
- logger.info("ServiceUUID used after upload in ulr:" + updatedServiceUUID);
- sdcServicesInformation = sdcCatalogServices.getSdcServicesInformation(updatedServiceUUID);
- CldsSdcServiceDetail = sdcCatalogServices.getCldsSdcServiceDetailFromJson(sdcServicesInformation);
- uploadedArtifactUUID = sdcCatalogServices.getArtifactIdIfArtifactAlreadyExists(CldsSdcServiceDetail,
- locationArtifactName);
- // To send location information also to sdc
- updateUrl = uploadedArtifactUUID != null ? url + "/" + uploadedArtifactUUID : url;
- responseStr = sdcCatalogServices.uploadArtifactToSdc(prop, userid, updateUrl,
- formattedSdcLocationReq);
- logger.info("value of sdc Response of uploading location to sdc :" + responseStr);
- }
- }
- }
- }
-
+ /**
+ * Method to get sdc service values from properties file.
+ * @param controlName
+ */
private void getSdcAttributes(String controlName) {
baseUrl = refProp.getStringValue("sdc.serviceUrl");
artifactLabel = SdcReq
diff --git a/src/main/java/org/onap/clamp/clds/exception/DcaeDeploymentException.java b/src/main/java/org/onap/clamp/clds/exception/DcaeDeploymentException.java
new file mode 100644
index 000000000..6a60ac9d9
--- /dev/null
+++ b/src/main/java/org/onap/clamp/clds/exception/DcaeDeploymentException.java
@@ -0,0 +1,61 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP CLAMP
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END============================================
+ * ===================================================================
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ */
+
+package org.onap.clamp.clds.exception;
+
+/**
+ * New exception to capture DCAE communication errors.
+ *
+ */
+public class DcaeDeploymentException extends RuntimeException {
+
+ /**
+ * Generated ID
+ */
+ private static final long serialVersionUID = 8452294782552680243L;
+
+ /**
+ * This constructor can be used to create a new DcaeDeploymentException.
+ *
+ * @param message
+ * A string message detailing the problem
+ * @param e
+ * The exception sent by the code
+ */
+ public DcaeDeploymentException(String message, Throwable e) {
+ super(message, e);
+ }
+
+ /**
+ * This constructor can be used to create a new DcaeDeploymentException. Use
+ * this constructor only if you are creating a new exception stack, not if
+ * an exception was already raised by another code.
+ *
+ * @param message
+ * A string message detailing the problem
+ */
+ public DcaeDeploymentException(String message) {
+ super(message);
+ }
+
+}
diff --git a/src/main/java/org/onap/clamp/clds/service/CldsService.java b/src/main/java/org/onap/clamp/clds/service/CldsService.java
index 509535c5b..c0f711165 100644
--- a/src/main/java/org/onap/clamp/clds/service/CldsService.java
+++ b/src/main/java/org/onap/clamp/clds/service/CldsService.java
@@ -76,6 +76,8 @@ import org.onap.clamp.clds.util.LoggingUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationContext;
+import org.springframework.http.HttpStatus;
+import org.springframework.web.client.HttpClientErrorException;
import com.att.ajsc.common.AjscService;
import com.att.eelf.configuration.EELFLogger;
@@ -97,38 +99,38 @@ import io.swagger.annotations.ApiOperation;
public class CldsService extends SecureServiceBase {
@Autowired
- private ApplicationContext appContext;
+ private ApplicationContext appContext;
- private static final String RESOURCE_NAME = "clds-version.properties";
+ private static final String RESOURCE_NAME = "clds-version.properties";
- protected static final EELFLogger logger = EELFManager.getInstance().getLogger(CldsService.class);
+ protected static final EELFLogger logger = EELFManager.getInstance().getLogger(CldsService.class);
protected static final EELFLogger auditLogger = EELFManager.getInstance().getAuditLogger();
@Value("${CLDS_PERMISSION_TYPE_CL:permission-type-cl}")
- private String cldsPersmissionTypeCl;
+ private String cldsPersmissionTypeCl;
@Value("${CLDS_PERMISSION_TYPE_CL_MANAGE:permission-type-cl-manage}")
- private String cldsPermissionTypeClManage;
+ private String cldsPermissionTypeClManage;
@Value("${CLDS_PERMISSION_TYPE_CL_EVENT:permission-type-cl-event}")
- private String cldsPermissionTypeClEvent;
+ private String cldsPermissionTypeClEvent;
@Value("${CLDS_PERMISSION_TYPE_FILTER_VF:permission-type-filter-vf}")
- private String cldsPermissionTypeFilterVf;
+ private String cldsPermissionTypeFilterVf;
@Value("${CLDS_PERMISSION_TYPE_TEMPLATE:permission-type-template}")
- private String cldsPermissionTypeTemplate;
+ private String cldsPermissionTypeTemplate;
@Value("${CLDS_PERMISSION_INSTANCE:dev}")
- private String cldsPermissionInstance;
+ private String cldsPermissionInstance;
- private SecureServicePermission permissionReadCl;
+ private SecureServicePermission permissionReadCl;
- private SecureServicePermission permissionUpdateCl;
+ private SecureServicePermission permissionUpdateCl;
- private SecureServicePermission permissionReadTemplate;
+ private SecureServicePermission permissionReadTemplate;
- private SecureServicePermission permissionUpdateTemplate;
+ private SecureServicePermission permissionUpdateTemplate;
@PostConstruct
private final void afterConstruction() {
@@ -212,10 +214,10 @@ public class CldsService extends SecureServiceBase {
cldsInfo.setCldsVersion(cldsVersion);
// Get the user list of permissions
- cldsInfo.setPermissionReadCl(isAuthorized(permissionReadCl));
- cldsInfo.setPermissionUpdateCl(isAuthorized(permissionUpdateCl));
- cldsInfo.setPermissionReadTemplate(isAuthorized(permissionReadTemplate));
- cldsInfo.setPermissionUpdateTemplate(isAuthorized(permissionUpdateTemplate));
+ cldsInfo.setPermissionReadCl(isAuthorizedNoException(permissionReadCl));
+ cldsInfo.setPermissionUpdateCl(isAuthorizedNoException(permissionUpdateCl));
+ cldsInfo.setPermissionReadTemplate(isAuthorizedNoException(permissionReadTemplate));
+ cldsInfo.setPermissionUpdateTemplate(isAuthorizedNoException(permissionUpdateTemplate));
return cldsInfo;
}
@@ -447,9 +449,9 @@ public class CldsService extends SecureServiceBase {
@Path("/model-names")
@Produces(MediaType.APPLICATION_JSON)
public List<ValueItem> getModelNames() {
- // isAuthorized(permissionReadCl);
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
@@ -522,10 +524,11 @@ public class CldsService extends SecureServiceBase {
String bpmnJson = cldsBpmnTransformer.doXslTransformToString(bpmn);
logger.info("PUT bpmnJson={}", bpmnJson);
- // Flag indicates whether it is triggered by Validation Test button from UI
+ // Flag indicates whether it is triggered by Validation Test button from
+ // UI
boolean isTest = false;
if (test != null && test.equalsIgnoreCase("true")) {
- isTest = true;
+ isTest = true;
} else {
// if action.test.override is true, then any action will be marked
// as test=true (even if incoming action request had test=false);
@@ -612,10 +615,11 @@ public class CldsService extends SecureServiceBase {
userid = getUserId();
}
- // Flag indicates whether it is triggered by Validation Test button from UI
+ // Flag indicates whether it is triggered by Validation Test button from
+ // UI
boolean isTest = false;
if (test != null && test.equalsIgnoreCase("true")) {
- isTest = true;
+ isTest = true;
}
int instanceCount = 0;
@@ -919,8 +923,8 @@ public class CldsService extends SecureServiceBase {
String operationStatus = "processing";
long waitingTime = System.nanoTime() + TimeUnit.MINUTES.toNanos(10);
while (operationStatus.equalsIgnoreCase("processing")) {
- //Break the loop if waiting for more than 10 mins
- if(waitingTime < System.nanoTime()){
+ // Break the loop if waiting for more than 10 mins
+ if (waitingTime < System.nanoTime()) {
break;
}
operationStatus = dcaeDispatcherServices.getOperationStatus(createNewDeploymentStatusUrl);
@@ -938,12 +942,12 @@ public class CldsService extends SecureServiceBase {
CldsEvent.ACTION_STATE_RECEIVED, null);
model.setDeploymentId(deploymentId);
model.save(cldsDao, getUserId());
+ } else {
+ logger.info("Deploy model (" + modelName + ") failed...Operation Status is - " + operationStatus);
+ throw new HttpClientErrorException(HttpStatus.INTERNAL_SERVER_ERROR,
+ "Deploy model (" + modelName + ") failed...Operation Status is - " + operationStatus);
}
- else{
- logger.info("Deploy model (" + modelName + ") failed...Operation Status is - " + operationStatus);
- throw new Exception("Deploy model (" + modelName + ") failed...Operation Status is - " + operationStatus);
- }
- logger.info("Deploy model (" + modelName + ") succeeded...Deployment Id is - " + deploymentId);
+ 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());
@@ -964,7 +968,7 @@ public class CldsService extends SecureServiceBase {
String operationStatus = "processing";
long waitingTime = System.nanoTime() + TimeUnit.MINUTES.toNanos(10);
while (operationStatus.equalsIgnoreCase("processing")) {
- if(waitingTime < System.nanoTime()){
+ if (waitingTime < System.nanoTime()) {
break;
}
operationStatus = dcaeDispatcherServices.getOperationStatus(operationStatusUndeployUrl);
@@ -982,13 +986,13 @@ public class CldsService extends SecureServiceBase {
CldsEvent.ACTION_STATE_RECEIVED, null);
model.setDeploymentId(null);
model.save(cldsDao, getUserId());
+ } else {
+ logger.info("Undeploy model (" + modelName + ") failed...Operation Status is - " + operationStatus);
+ throw new HttpClientErrorException(HttpStatus.INTERNAL_SERVER_ERROR,
+ "Undeploy model (" + modelName + ") failed...Operation Status is - " + operationStatus);
}
- else{
- logger.info("Undeploy model (" + modelName + ") failed...Operation Status is - " + operationStatus);
- throw new Exception("Undeploy model (" + modelName + ") failed...Operation Status is - " + operationStatus);
- }
- logger.info("Undeploy model (" + modelName + ") succeeded.");
- // audit log
+ 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");
diff --git a/src/main/java/org/onap/clamp/clds/service/SecureServiceBase.java b/src/main/java/org/onap/clamp/clds/service/SecureServiceBase.java
index 89e6c092a..19813ebaf 100644
--- a/src/main/java/org/onap/clamp/clds/service/SecureServiceBase.java
+++ b/src/main/java/org/onap/clamp/clds/service/SecureServiceBase.java
@@ -38,14 +38,14 @@ import com.att.eelf.configuration.EELFManager;
* Base/abstract Service class. Implements shared security methods.
*/
public abstract class SecureServiceBase {
- protected static final EELFLogger logger = EELFManager.getInstance().getLogger(SecureServiceBase.class);
+ protected static final EELFLogger logger = EELFManager.getInstance().getLogger(SecureServiceBase.class);
protected static final EELFLogger auditLogger = EELFManager.getInstance().getAuditLogger();
// By default we'll set it to a default handler
- private static UserNameHandler userNameHandler = new DefaultUserNameHandler();
+ private static UserNameHandler userNameHandler = new DefaultUserNameHandler();
@Context
- private SecurityContext securityContext;
+ private SecurityContext securityContext;
/**
* Get the userId from AAF/CSP.
@@ -91,8 +91,12 @@ public abstract class SecureServiceBase {
* app-perm-type|dev|read
*
* @param inPermission
- * @return
+ * The permission to validate
+ * @return A boolean to indicate if the user has the permission to do
+ * execute the inPermission
* @throws NotAuthorizedException
+ * In case of issues with the permission test, error is returned
+ * in this exception
*/
public boolean isAuthorized(SecureServicePermission inPermission) throws NotAuthorizedException {
boolean authorized = false;
@@ -133,11 +137,12 @@ public abstract class SecureServiceBase {
* it will be authorized if the inPermission to check is:
* app-perm-type|dev|read
*
- * @param aafPermission
- * @return
- * @throws NotAuthorizedException
+ * @param inPermission
+ * The permission to validate
+ * @return A boolean to indicate if the user has the permission to do
+ * execute the inPermission
*/
- public boolean isAuthorizedNoException(SecureServicePermission inPermission) throws NotAuthorizedException {
+ public boolean isAuthorizedNoException(SecureServicePermission inPermission) {
boolean authorized = false;
logger.debug("checking if {} has permission: {}", getPrincipalName(), inPermission);
// check if the user has the permission key or the permission key with a
@@ -167,6 +172,14 @@ public abstract class SecureServiceBase {
return authorized;
}
+ /**
+ * This method can be used by the Application.class to set the
+ * UserNameHandler that must be used in this class. The UserNameHandler
+ * where to get the User name
+ *
+ * @param handler
+ * The Handler impl to use
+ */
public static final void setUserNameHandler(UserNameHandler handler) {
if (handler != null) {
userNameHandler = handler;