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/exception/policy/PolicyModelException.java31
-rw-r--r--src/main/java/org/onap/clamp/clds/model/CldsToscaModel.java24
-rw-r--r--src/main/java/org/onap/clamp/clds/sdc/controller/SdcSingleController.java7
-rw-r--r--src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarHandler.java15
-rw-r--r--src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarInstaller.java4
-rw-r--r--src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarInstallerImpl.java15
-rw-r--r--src/main/java/org/onap/clamp/clds/service/CldsService.java5
-rw-r--r--src/main/java/org/onap/clamp/clds/service/CldsToscaService.java14
8 files changed, 85 insertions, 30 deletions
diff --git a/src/main/java/org/onap/clamp/clds/exception/policy/PolicyModelException.java b/src/main/java/org/onap/clamp/clds/exception/policy/PolicyModelException.java
new file mode 100644
index 000000000..0b64b78ea
--- /dev/null
+++ b/src/main/java/org/onap/clamp/clds/exception/policy/PolicyModelException.java
@@ -0,0 +1,31 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP CLAMP
+ * ================================================================================
+ * Copyright (C) 2019 Nokia 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============================================
+ * ===================================================================
+ *
+ */
+
+package org.onap.clamp.clds.exception.policy;
+
+public class PolicyModelException extends Exception {
+
+ public PolicyModelException(String msg, Throwable throwable) {
+ super(msg, throwable);
+ }
+}
diff --git a/src/main/java/org/onap/clamp/clds/model/CldsToscaModel.java b/src/main/java/org/onap/clamp/clds/model/CldsToscaModel.java
index 25b8d4016..6184b3946 100644
--- a/src/main/java/org/onap/clamp/clds/model/CldsToscaModel.java
+++ b/src/main/java/org/onap/clamp/clds/model/CldsToscaModel.java
@@ -36,7 +36,12 @@ public class CldsToscaModel extends CldsToscaModelRevision {
private String id;
private String policyType;
private String toscaModelName;
- private String toscaModelYaml;
+
+ /**
+ * Construct
+ */
+ public CldsToscaModel () {
+ }
/**
* Creates or updates Tosca Model to DB
@@ -123,21 +128,4 @@ public class CldsToscaModel extends CldsToscaModelRevision {
this.toscaModelName = toscaModelName;
}
- /**
- * @return the toscaModelYaml
- */
- @Override
- public String getToscaModelYaml() {
- return toscaModelYaml;
- }
-
- /**
- * @param toscaModelYaml
- * the toscaModelYaml to set
- */
- @Override
- public void setToscaModelYaml(String toscaModelYaml) {
- this.toscaModelYaml = toscaModelYaml;
- }
-
}
diff --git a/src/main/java/org/onap/clamp/clds/sdc/controller/SdcSingleController.java b/src/main/java/org/onap/clamp/clds/sdc/controller/SdcSingleController.java
index 5959c0fb5..c9405d202 100644
--- a/src/main/java/org/onap/clamp/clds/sdc/controller/SdcSingleController.java
+++ b/src/main/java/org/onap/clamp/clds/sdc/controller/SdcSingleController.java
@@ -33,6 +33,7 @@ import java.util.concurrent.ThreadLocalRandom;
import org.onap.clamp.clds.config.ClampProperties;
import org.onap.clamp.clds.config.sdc.SdcSingleControllerConfiguration;
+import org.onap.clamp.clds.exception.policy.PolicyModelException;
import org.onap.clamp.clds.exception.sdc.controller.CsarHandlerException;
import org.onap.clamp.clds.exception.sdc.controller.SdcArtifactInstallerException;
import org.onap.clamp.clds.exception.sdc.controller.SdcControllerException;
@@ -257,6 +258,10 @@ public class SdcSingleController {
logger.error("SdcDownloadException exception caught during the notification processing", e);
sendAllNotificationForCsarHandler(iNotif, csar, NotificationType.DOWNLOAD,
DistributionStatusEnum.DOWNLOAD_ERROR, e.getMessage());
+ } catch (PolicyModelException e) {
+ logger.error("PolicyModelException exception caught during the notification processing", e);
+ sendAllNotificationForCsarHandler(iNotif, csar, NotificationType.DEPLOY,
+ DistributionStatusEnum.DEPLOY_ERROR, e.getMessage());
} catch (InterruptedException e) {
logger.error("Interrupt exception caught during the notification processing", e);
sendAllNotificationForCsarHandler(iNotif, csar, NotificationType.DEPLOY,
@@ -266,7 +271,7 @@ public class SdcSingleController {
logger.error("Unexpected exception caught during the notification processing", e);
sendAllNotificationForCsarHandler(iNotif, csar, NotificationType.DEPLOY,
DistributionStatusEnum.DEPLOY_ERROR, e.getMessage());
- } finally {
+ } finally {
this.changeControllerStatus(SdcSingleControllerStatus.IDLE);
}
}
diff --git a/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarHandler.java b/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarHandler.java
index 1a99919ee..f2c75ef28 100644
--- a/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarHandler.java
+++ b/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarHandler.java
@@ -36,6 +36,7 @@ import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
@@ -68,6 +69,7 @@ public class CsarHandler {
private INotificationData sdcNotification;
public static final String RESOURCE_INSTANCE_NAME_PREFIX = "/Artifacts/Resources/";
public static final String RESOURCE_INSTANCE_NAME_SUFFIX = "/Deployment/";
+ public static final String POLICY_DEFINITION_NAME_SUFFIX = "Definitions/policies.yml";
public CsarHandler(INotificationData iNotif, String controller, String clampCsarPath) throws CsarHandlerException {
this.sdcNotification = iNotif;
@@ -167,4 +169,17 @@ public class CsarHandler {
public Map<String, BlueprintArtifact> getMapOfBlueprints() {
return mapOfBlueprints;
}
+
+ Optional<String> getPolicyModelYaml() throws IOException {
+ String result = null;
+ try (ZipFile zipFile = new ZipFile(csarFilePath)) {
+ ZipEntry entry = zipFile.getEntry(POLICY_DEFINITION_NAME_SUFFIX);
+ if (entry != null) {
+ result = IOUtils.toString(zipFile.getInputStream(entry));
+ } else{
+ logger.info("Policy model not found inside the CSAR file: " + csarFilePath);
+ }
+ return Optional.ofNullable(result);
+ }
+ }
}
diff --git a/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarInstaller.java b/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarInstaller.java
index b5c025ecb..12a761dbf 100644
--- a/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarInstaller.java
+++ b/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarInstaller.java
@@ -23,11 +23,13 @@
package org.onap.clamp.clds.sdc.controller.installer;
+import org.onap.clamp.clds.exception.policy.PolicyModelException;
import org.onap.clamp.clds.exception.sdc.controller.SdcArtifactInstallerException;
public interface CsarInstaller {
boolean isCsarAlreadyDeployed(CsarHandler csar) throws SdcArtifactInstallerException;
- public void installTheCsar(CsarHandler csar) throws SdcArtifactInstallerException, InterruptedException;
+ public void installTheCsar(CsarHandler csar)
+ throws SdcArtifactInstallerException, InterruptedException, PolicyModelException;
}
diff --git a/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarInstallerImpl.java b/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarInstallerImpl.java
index bfda6924d..6841b87b0 100644
--- a/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarInstallerImpl.java
+++ b/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarInstallerImpl.java
@@ -34,6 +34,7 @@ import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
+import java.util.Optional;
import javax.annotation.PostConstruct;
import javax.xml.transform.TransformerException;
@@ -43,6 +44,7 @@ import org.onap.clamp.clds.client.DcaeInventoryServices;
import org.onap.clamp.clds.config.sdc.BlueprintParserFilesConfiguration;
import org.onap.clamp.clds.config.sdc.BlueprintParserMappingConfiguration;
import org.onap.clamp.clds.dao.CldsDao;
+import org.onap.clamp.clds.exception.policy.PolicyModelException;
import org.onap.clamp.clds.exception.sdc.controller.SdcArtifactInstallerException;
import org.onap.clamp.clds.model.CldsModel;
import org.onap.clamp.clds.model.CldsTemplate;
@@ -125,7 +127,8 @@ public class CsarInstallerImpl implements CsarInstaller {
@Override
@Transactional
- public void installTheCsar(CsarHandler csar) throws SdcArtifactInstallerException, InterruptedException {
+ public void installTheCsar(CsarHandler csar)
+ throws SdcArtifactInstallerException, InterruptedException, PolicyModelException {
try {
logger.info("Installing the CSAR " + csar.getFilePath());
for (Entry<String, BlueprintArtifact> blueprint : csar.getMapOfBlueprints().entrySet()) {
@@ -135,6 +138,7 @@ public class CsarInstallerImpl implements CsarInstaller {
this.searchForRightMapping(blueprint.getValue())),
queryDcaeToGetServiceTypeId(blueprint.getValue()));
}
+ createPolicyModel(csar);
logger.info("Successfully installed the CSAR " + csar.getFilePath());
} catch (IOException e) {
throw new SdcArtifactInstallerException("Exception caught during the Csar installation in database", e);
@@ -143,6 +147,15 @@ public class CsarInstallerImpl implements CsarInstaller {
}
}
+ private void createPolicyModel(CsarHandler csar) throws PolicyModelException {
+ try{
+ Optional<String> policyModelYaml = csar.getPolicyModelYaml();
+ // save policy model into the database
+ } catch (IOException e) {
+ throw new PolicyModelException("TransformerException when decoding the YamlText", e);
+ }
+ }
+
private BlueprintParserFilesConfiguration searchForRightMapping(BlueprintArtifact blueprintArtifact)
throws SdcArtifactInstallerException {
List<BlueprintParserFilesConfiguration> listConfig = new ArrayList<>();
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 42e9cf713..e3a379b36 100644
--- a/src/main/java/org/onap/clamp/clds/service/CldsService.java
+++ b/src/main/java/org/onap/clamp/clds/service/CldsService.java
@@ -394,11 +394,14 @@ public class CldsService extends SecureServiceBase {
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);
diff --git a/src/main/java/org/onap/clamp/clds/service/CldsToscaService.java b/src/main/java/org/onap/clamp/clds/service/CldsToscaService.java
index 04205b704..adebd7853 100644
--- a/src/main/java/org/onap/clamp/clds/service/CldsToscaService.java
+++ b/src/main/java/org/onap/clamp/clds/service/CldsToscaService.java
@@ -101,7 +101,7 @@ public class CldsToscaService extends SecureServiceBase {
*
* @return clds tosca models - list of CLDS tosca models
*/
- public ResponseEntity<List<CldsToscaModel>> getAllToscaModels() {
+ public List<CldsToscaModel> getAllToscaModels() {
Date startTime = new Date();
LoggingUtils.setRequestContext("CldsToscaService: Get All tosca models", getPrincipalName());
@@ -111,7 +111,7 @@ public class CldsToscaService extends SecureServiceBase {
LoggingUtils.setTimeContext(startTime, new Date());
LoggingUtils.setResponseContext("0", "Get All tosca models success", this.getClass().getName());
auditLogger.info("Get All tosca models");
- return new ResponseEntity<>(cldsToscaModels, HttpStatus.OK);
+ return cldsToscaModels;
}
/**
@@ -123,7 +123,7 @@ public class CldsToscaService extends SecureServiceBase {
*
* @return clds tosca model - CLDS tosca model for a given tosca model name
*/
- public ResponseEntity<CldsToscaModel> getToscaModel(String toscaModelName) {
+ public CldsToscaModel getToscaModel(String toscaModelName) {
Date startTime = new Date();
LoggingUtils.setRequestContext("CldsToscaService: Get tosca models by model name", getPrincipalName());
// TODO revisit based on new permissions
@@ -132,8 +132,7 @@ public class CldsToscaService extends SecureServiceBase {
LoggingUtils.setTimeContext(startTime, new Date());
LoggingUtils.setResponseContext("0", "Get tosca models by model name success", this.getClass().getName());
auditLogger.info("GET tosca models by model name completed");
- return new ResponseEntity<>(Optional.ofNullable(cldsToscaModels).get().stream().findFirst().get(),
- HttpStatus.OK);
+ return cldsToscaModels.get(0);
}
/**
@@ -143,7 +142,7 @@ public class CldsToscaService extends SecureServiceBase {
* @param policyType
* @return clds tosca model - CLDS tosca model for a given policy type
*/
- public ResponseEntity<CldsToscaModel> getToscaModelsByPolicyType(String policyType) {
+ public CldsToscaModel getToscaModelsByPolicyType(String policyType) {
Date startTime = new Date();
LoggingUtils.setRequestContext("CldsToscaService: Get tosca models by policyType", getPrincipalName());
// TODO revisit based on new permissions
@@ -152,8 +151,7 @@ public class CldsToscaService extends SecureServiceBase {
LoggingUtils.setTimeContext(startTime, new Date());
LoggingUtils.setResponseContext("0", "Get tosca models by policyType success", this.getClass().getName());
auditLogger.info("GET tosca models by policyType completed");
- return new ResponseEntity<>(Optional.ofNullable(cldsToscaModels).get().stream().findFirst().get(),
- HttpStatus.OK);
+ return cldsToscaModels.get(0);
}
public ResponseEntity<?> deleteToscaModelById(String toscaModeId) {