2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights
7 * ================================================================================
8 * Modifications Copyright (c) 2019 Samsung
9 * ================================================================================
10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
14 * http://www.apache.org/licenses/LICENSE-2.0
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
21 * ============LICENSE_END============================================
22 * ===================================================================
26 package org.onap.clamp.clds.client.req.policy;
28 import com.att.eelf.configuration.EELFLogger;
29 import com.att.eelf.configuration.EELFManager;
31 import java.io.IOException;
32 import java.io.OutputStream;
33 import java.nio.file.Files;
34 import java.nio.file.Path;
35 import java.nio.file.Paths;
36 import java.util.Collection;
37 import java.util.Date;
39 import java.util.UUID;
41 import javax.ws.rs.BadRequestException;
43 import org.onap.clamp.clds.config.ClampProperties;
44 import org.onap.clamp.clds.config.PolicyConfiguration;
45 import org.onap.clamp.clds.exception.policy.PolicyClientException;
46 import org.onap.clamp.clds.model.CldsToscaModel;
47 import org.onap.clamp.clds.model.properties.ModelProperties;
48 import org.onap.clamp.clds.model.properties.PolicyItem;
49 import org.onap.clamp.clds.util.LoggingUtils;
50 import org.onap.policy.api.AttributeType;
51 import org.onap.policy.api.ConfigRequestParameters;
52 import org.onap.policy.api.DeletePolicyCondition;
53 import org.onap.policy.api.DeletePolicyParameters;
54 import org.onap.policy.api.DictionaryType;
55 import org.onap.policy.api.ImportParameters;
56 import org.onap.policy.api.ImportParameters.IMPORT_TYPE;
57 import org.onap.policy.api.PolicyChangeResponse;
58 import org.onap.policy.api.PolicyClass;
59 import org.onap.policy.api.PolicyConfigException;
60 import org.onap.policy.api.PolicyConfigType;
61 import org.onap.policy.api.PolicyEngine;
62 import org.onap.policy.api.PolicyEngineException;
63 import org.onap.policy.api.PolicyParameters;
64 import org.onap.policy.api.PolicyType;
65 import org.onap.policy.api.PushPolicyParameters;
66 import org.onap.policy.api.RuleProvider;
67 import org.springframework.beans.factory.annotation.Autowired;
68 import org.springframework.context.ApplicationContext;
69 import org.springframework.context.annotation.Primary;
70 import org.springframework.stereotype.Component;
73 * Policy utility methods - specifically, send the policy.
77 public class PolicyClient {
79 protected PolicyEngine policyEngine;
80 protected static final String LOG_POLICY_PREFIX = "Response is ";
81 protected static final EELFLogger logger = EELFManager.getInstance().getLogger(PolicyClient.class);
82 protected static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger();
83 public static final String POLICY_MSTYPE_PROPERTY_NAME = "policy.ms.type";
84 public static final String POLICY_ONAPNAME_PROPERTY_NAME = "policy.onap.name";
85 public static final String POLICY_BASENAME_PREFIX_PROPERTY_NAME = "policy.base.policyNamePrefix";
86 public static final String POLICY_OP_NAME_PREFIX_PROPERTY_NAME = "policy.op.policyNamePrefix";
87 public static final String POLICY_MS_NAME_PREFIX_PROPERTY_NAME = "policy.ms.policyNamePrefix";
88 public static final String POLICY_OP_TYPE_PROPERTY_NAME = "policy.op.type";
89 public static final String TOSCA_FILE_TEMP_PATH = "tosca.filePath";
92 protected ApplicationContext appContext;
94 protected ClampProperties refProp;
96 private PolicyConfiguration policyConfiguration;
99 * Perform Guard policy type.
102 * A map of attributes
104 * The ModelProperties
105 * @param policyRequestUuid
107 * @return The response message of policy
109 public String sendGuardPolicy(Map<AttributeType, Map<String, String>> attributes, ModelProperties prop,
110 String policyRequestUuid, PolicyItem policyItem) {
111 PolicyParameters policyParameters = new PolicyParameters();
112 // Set Policy Type(Mandatory)
113 policyParameters.setPolicyClass(PolicyClass.Decision);
114 // Set Policy Name(Mandatory)
115 policyParameters.setPolicyName(prop.getPolicyScopeAndNameWithUniqueGuardId());
116 // documentation says this is options, but when tested, got the
117 // following failure: java.lang.Exception: Policy send failed: PE300 -
118 // Data Issue: No policyDescription given.
119 policyParameters.setPolicyDescription(refProp.getStringValue("op.policyDescription"));
120 policyParameters.setOnapName("PDPD");
121 policyParameters.setRuleProvider(RuleProvider.valueOf(policyItem.getGuardPolicyType()));
122 policyParameters.setAttributes(attributes);
123 // Set a random UUID(Mandatory)
124 policyParameters.setRequestID(UUID.fromString(policyRequestUuid));
126 String rtnMsg = send(policyParameters, prop, null, null);
127 push(DictionaryType.Decision.toString(), prop, null);
132 * Perform BRMS policy type.
135 * A map of attributes
137 * The ModelProperties
138 * @param policyRequestUuid
140 * @return The response message of policy
142 public String sendBrmsPolicy(Map<AttributeType, Map<String, String>> attributes, ModelProperties prop,
143 String policyRequestUuid) {
144 PolicyParameters policyParameters = new PolicyParameters();
145 // Set Policy Type(Mandatory)
146 policyParameters.setPolicyConfigType(PolicyConfigType.BRMS_PARAM);
147 // Set Policy Name(Mandatory)
148 policyParameters.setPolicyName(prop.getPolicyScopeAndNameWithUniqueId());
149 // documentation says this is options, but when tested, got the
150 // following failure: java.lang.Exception: Policy send failed: PE300 -
151 // Data Issue: No policyDescription given.
152 policyParameters.setPolicyDescription(refProp.getStringValue("op.policyDescription"));
153 policyParameters.setAttributes(attributes);
154 // Set a random UUID(Mandatory)
155 policyParameters.setRequestID(UUID.fromString(policyRequestUuid));
156 String policyNamePrefix = refProp.getStringValue(POLICY_OP_NAME_PREFIX_PROPERTY_NAME);
157 String rtnMsg = send(policyParameters, prop, policyNamePrefix, null);
158 String policyType = refProp.getStringValue(POLICY_OP_TYPE_PROPERTY_NAME);
159 push(policyType, prop, null);
164 * Perform send of microservice policy in JSON.
169 * The ModelProperties
170 * @param policyRequestUuid
171 * The policy Request UUID
172 * @return The response message of policy
174 public String sendMicroServiceInJson(String policyJson, ModelProperties prop, String policyRequestUuid) {
175 PolicyParameters policyParameters = new PolicyParameters();
177 policyParameters.setPolicyConfigType(PolicyConfigType.MicroService);
178 policyParameters.setOnapName(refProp.getStringValue(POLICY_ONAPNAME_PROPERTY_NAME));
179 policyParameters.setPolicyName(prop.getCurrentPolicyScopeAndPolicyName());
180 policyParameters.setConfigBody(policyJson);
181 policyParameters.setConfigBodyType(PolicyType.JSON);
182 policyParameters.setRequestID(UUID.fromString(policyRequestUuid));
183 String policyNamePrefix = refProp.getStringValue(POLICY_MS_NAME_PREFIX_PROPERTY_NAME);
184 // Adding this line to clear the policy id from policy name while
185 // pushing to policy engine
186 prop.setPolicyUniqueId("");
187 String rtnMsg = send(policyParameters, prop, policyNamePrefix, null);
188 String policyType = refProp.getStringValue(POLICY_MSTYPE_PROPERTY_NAME);
189 push(policyType, prop, null);
194 * Perform send of base policy in OTHER type.
197 * The config policy string body
198 * @param configPolicyName
199 * The config policy name of the component that has been pre-deployed in
202 * The ModelProperties
203 * @param policyRequestUuid
204 * The policy request UUID
205 * @return The answer from policy call
207 public String sendBasePolicyInOther(String configBody, String configPolicyName, ModelProperties prop,
208 String policyRequestUuid) {
209 PolicyParameters policyParameters = new PolicyParameters();
211 policyParameters.setPolicyConfigType(PolicyConfigType.Base);
212 policyParameters.setOnapName(refProp.getStringValue(POLICY_ONAPNAME_PROPERTY_NAME));
213 policyParameters.setPolicyName(prop.getCurrentPolicyScopeAndPolicyName());
214 policyParameters.setConfigBody(configBody);
215 policyParameters.setConfigBodyType(PolicyType.OTHER);
216 policyParameters.setConfigName("HolmesPolicy");
217 policyParameters.setPolicyName(configPolicyName);
218 policyParameters.setRequestID(UUID.fromString(policyRequestUuid));
219 // Adding this line to clear the policy id from policy name while
220 // pushing to policy engine
221 prop.setPolicyUniqueId("");
222 String rtnMsg = send(policyParameters, prop, refProp.getStringValue(POLICY_BASENAME_PREFIX_PROPERTY_NAME),
224 push(PolicyConfigType.Base.toString(), prop, null);
229 * Perform send of Microservice policy in OTHER type.
232 * The config policy string body
234 * The ModelProperties
235 * @return The answer from policy call
237 public String sendMicroServiceInOther(String configBody, ModelProperties prop) {
238 PolicyParameters policyParameters = new PolicyParameters();
240 policyParameters.setPolicyConfigType(PolicyConfigType.MicroService);
241 policyParameters.setOnapName(refProp.getStringValue(POLICY_ONAPNAME_PROPERTY_NAME));
242 policyParameters.setPolicyName(prop.getCurrentPolicyScopeAndPolicyName());
243 policyParameters.setConfigBody(configBody);
244 String policyNamePrefix = refProp.getStringValue(POLICY_MS_NAME_PREFIX_PROPERTY_NAME);
245 // Adding this line to clear the policy id from policy name while
246 // pushing to policy engine
247 prop.setPolicyUniqueId("");
248 String rtnMsg = send(policyParameters, prop, policyNamePrefix, null);
249 String policyType = refProp.getStringValue(POLICY_MSTYPE_PROPERTY_NAME);
250 push(policyType, prop, null);
255 * Perform send of Configuration or Decision policies.
257 * @param policyParameters
258 * The PolicyParameters
260 * The ModelProperties
261 * @return The response message of Policy
263 protected String send(PolicyParameters policyParameters, ModelProperties prop, String policyPrefix,
264 String policyNameWithPrefix) {
265 // Verify whether it is triggered by Validation Test button from UI
266 if (prop.isTestOnly()) {
267 return "send not executed for test action";
269 // API method to create or update Policy.
270 PolicyChangeResponse response = null;
271 String responseMessage = "";
272 Date startTime = new Date();
274 if ((PolicyClass.Decision.equals(policyParameters.getPolicyClass()) && !checkDecisionPolicyExists(prop))
275 || (PolicyClass.Config.equals(policyParameters.getPolicyClass())
276 && !checkPolicyExists(prop, policyPrefix, policyNameWithPrefix))) {
277 LoggingUtils.setTargetContext("Policy", "createPolicy");
278 logger.info("Attempting to create policy for action=" + prop.getActionCd());
279 response = getPolicyEngine().createPolicy(policyParameters);
280 responseMessage = response.getResponseMessage();
282 LoggingUtils.setTargetContext("Policy", "updatePolicy");
283 logger.info("Attempting to update policy for action=" + prop.getActionCd());
284 response = getPolicyEngine().updatePolicy(policyParameters);
285 responseMessage = response.getResponseMessage();
287 } catch (Exception e) {
288 LoggingUtils.setResponseContext("900", "Policy send failed", this.getClass().getName());
289 LoggingUtils.setErrorContext("900", "Policy send error");
290 logger.error("Exception occurred during policy communication", e);
291 throw new PolicyClientException("Exception while communicating with Policy", e);
293 logger.info(LOG_POLICY_PREFIX + responseMessage);
294 LoggingUtils.setTimeContext(startTime, new Date());
295 if (response.getResponseCode() == 200) {
296 LoggingUtils.setResponseContext("0", "Policy send success", this.getClass().getName());
297 logger.info("Policy send successful");
298 metricsLogger.info("Policy send success");
300 LoggingUtils.setResponseContext("900", "Policy send failed", this.getClass().getName());
301 logger.warn("Policy send failed: " + responseMessage);
302 metricsLogger.info("Policy send failure");
303 throw new BadRequestException("Policy send failed: " + responseMessage);
305 return responseMessage;
309 * Format and send push of policy.
314 * The ModelProperties
315 * @return The response message of policy
317 protected String push(String policyType, ModelProperties prop, String policyName) {
318 // Verify whether it is triggered by Validation Test button from UI
319 if (prop.isTestOnly()) {
320 return "push not executed for test action";
322 PushPolicyParameters pushPolicyParameters = new PushPolicyParameters();
323 pushPolicyParameters.setPolicyName(selectRightPolicyName(prop, policyType, policyName));
324 logger.info("Policy Name in Push policy method - " + pushPolicyParameters.getPolicyName());
325 pushPolicyParameters.setPolicyType(policyType);
326 pushPolicyParameters.setPdpGroup(refProp.getStringValue("policy.pdp.group"));
327 pushPolicyParameters.setRequestID(null);
328 // API method to create or update Policy.
329 PolicyChangeResponse response;
330 String responseMessage = "";
332 LoggingUtils.setTargetContext("Policy", "pushPolicy");
333 logger.info("Attempting to push policy...");
334 response = getPolicyEngine().pushPolicy(pushPolicyParameters);
335 if (response != null) {
336 responseMessage = response.getResponseMessage();
338 } catch (Exception e) {
339 LoggingUtils.setResponseContext("900", "Policy push failed", this.getClass().getName());
340 LoggingUtils.setErrorContext("900", "Policy push error");
341 logger.error("Exception occurred during policy communication", e);
342 throw new PolicyClientException("Exception while communicating with Policy", e);
344 logger.info(LOG_POLICY_PREFIX + responseMessage);
345 if (response != null && (response.getResponseCode() == 200 || response.getResponseCode() == 204)) {
346 LoggingUtils.setResponseContext("0", "Policy push success", this.getClass().getName());
347 logger.info("Policy push successful");
348 metricsLogger.info("Policy push success");
350 LoggingUtils.setResponseContext("900", "Policy push failed", this.getClass().getName());
351 logger.warn("Policy push failed: " + responseMessage);
352 metricsLogger.info("Policy push failure");
353 throw new BadRequestException("Policy push failed: " + responseMessage);
355 return responseMessage;
359 * Use list Decision policy to know if the decision policy exists.
362 * The model properties
363 * @return true if it exists, false otherwise
365 protected boolean checkDecisionPolicyExists(ModelProperties prop) {
366 boolean policyexists = false;
368 logger.info("Search in Policy Engine for DecisionpolicyName=" + prop.getPolicyScopeAndNameWithUniqueGuardId());
370 // No other choice than pushing to see if it exists or not
371 String response = push(DictionaryType.Decision.toString(), prop, null);
372 if (response != null) {
375 } catch (BadRequestException e) {
376 // just print warning - if no policy version found
377 logger.warn("Policy not found...policy name - " + prop.getPolicyScopeAndNameWithUniqueGuardId(), e);
383 * Use list Policy API to retrieve the policy. Return true if policy exists
384 * otherwise return false.
387 * The ModelProperties
388 * @param policyPrefix
389 * The Policy Name Prefix
390 * @param policyNameWithPrefix
391 * The Policy Full Name
392 * @return The response message from policy
393 * @throws PolicyConfigException
394 * In case of issues with policy engine
396 protected boolean checkPolicyExists(ModelProperties prop, String policyPrefix, String policyNameWithPrefix) {
397 boolean policyexists = false;
398 String policyName = "";
400 policyName = selectRightPolicyNameWithPrefix(prop, policyPrefix, policyNameWithPrefix);
401 logger.info("Search in Policy Engine for policyName=" + policyName);
403 ConfigRequestParameters configRequestParameters = new ConfigRequestParameters();
404 configRequestParameters.setPolicyName(policyName);
405 Collection<String> response = getPolicyEngine().listConfig(configRequestParameters);
406 if (response != null && !response.isEmpty() && !response.contains("Policy Name: null")) {
409 } catch (PolicyConfigException e1) {
410 // just print warning - if no policy version found
411 logger.warn("Policy not found...policy name - " + policyName, e1);
417 * This method create a new policy engine.
419 * @return A new policy engine
421 private synchronized PolicyEngine getPolicyEngine() {
423 if (policyEngine == null) {
424 policyEngine = new PolicyEngine(policyConfiguration.getProperties());
426 } catch (PolicyEngineException e) {
427 throw new PolicyClientException("Exception when creating a new policy engine", e);
433 * Format and send delete Micro Service requests to Policy.
436 * The ModelProperties
437 * @return The response message from Policy
439 public String deleteMicrosService(ModelProperties prop) {
440 return findAndDelete(prop, POLICY_MS_NAME_PREFIX_PROPERTY_NAME, POLICY_MSTYPE_PROPERTY_NAME);
444 * This method delete the Base policy.
447 * The model Properties
448 * @return A string with the answer from policy
450 public String deleteBasePolicy(ModelProperties prop) {
451 return deletePolicy(prop, PolicyConfigType.Base.toString(), null);
455 * Format and send delete Guard requests to Policy.
458 * The ModelProperties
459 * @return The response message from policy
461 public String deleteGuard(ModelProperties prop) {
462 String deletePolicyResponse = "";
465 if (checkDecisionPolicyExists(prop)) {
466 deletePolicyResponse = deletePolicy(prop, DictionaryType.Decision.toString(), null);
468 } catch (Exception e) {
469 logger.error("Exception occurred during policy communication", e);
470 throw new PolicyClientException("Exception while communicating with Policy", e);
472 return deletePolicyResponse;
476 * Format and send delete BRMS requests to Policy.
479 * The ModelProperties
480 * @return The response message from policy
482 public String deleteBrms(ModelProperties prop) {
483 return findAndDelete(prop, POLICY_OP_NAME_PREFIX_PROPERTY_NAME, POLICY_OP_TYPE_PROPERTY_NAME);
486 private String findAndDelete(ModelProperties prop, String policyPrefixProperty, String policyTypeProperty) {
487 String deletePolicyResponse = "";
489 String policyNamePrefix = refProp.getStringValue(policyPrefixProperty);
490 if (checkPolicyExists(prop, policyNamePrefix, null)) {
491 String policyType = refProp.getStringValue(policyTypeProperty);
492 deletePolicyResponse = deletePolicy(prop, policyType, null);
494 } catch (Exception e) {
495 logger.error("Exception occurred during policy communication", e);
496 throw new PolicyClientException("Exception while communicating with Policy", e);
498 return deletePolicyResponse;
501 protected String selectRightPolicyName(ModelProperties prop, String policyType, String policyName) {
502 if (policyName == null) {
503 if (prop.getPolicyUniqueId() != null && !prop.getPolicyUniqueId().isEmpty()) {
504 if (DictionaryType.Decision.toString().equals(policyType)) {
505 return prop.getPolicyScopeAndNameWithUniqueGuardId();
507 return prop.getPolicyScopeAndNameWithUniqueId();
510 return prop.getCurrentPolicyScopeAndPolicyName();
518 * Method to return correct policy name with prefix.
521 * The ModelProperties
522 * @param policyPrefix
524 * @param policyNameWithPrefix
525 * Policy Name With Prefix
526 * @return The policy name with the prefix
528 protected String selectRightPolicyNameWithPrefix(ModelProperties prop, String policyPrefix,
529 String policyNameWithPrefix) {
530 if (policyNameWithPrefix == null) {
531 if (prop.getPolicyUniqueId() != null && !prop.getPolicyUniqueId().isEmpty()) {
532 return prop.getCurrentPolicyScopeAndFullPolicyName(policyPrefix) + "_" + prop.getPolicyUniqueId();
534 return prop.getCurrentPolicyScopeAndFullPolicyName(policyPrefix);
537 return policyNameWithPrefix;
542 * Format and send delete PAP and PDP requests to Policy.
545 * The ModelProperties
547 * The policyType "Decision" or
548 * @return The response message from policy
550 protected String deletePolicy(ModelProperties prop, String policyType, String policyName) {
551 DeletePolicyParameters deletePolicyParameters = new DeletePolicyParameters();
552 deletePolicyParameters.setPolicyName(selectRightPolicyName(prop, policyType, policyName));
553 logger.info("Policy Name in delete policy method - " + deletePolicyParameters.getPolicyName());
554 logger.info("Deleting policy from PDP...");
555 deletePolicyParameters.setPolicyComponent("PDP");
556 deletePolicyParameters.setDeleteCondition(DeletePolicyCondition.ALL);
557 deletePolicyParameters.setPdpGroup(refProp.getStringValue("policy.pdp.group"));
558 deletePolicyParameters.setPolicyType(policyType);
559 // send delete request
560 logger.info("Deleting policy from PAP...");
561 StringBuilder responseMessage = new StringBuilder(sendDeletePolicy(deletePolicyParameters, prop));
562 deletePolicyParameters.setPolicyComponent("PAP");
563 deletePolicyParameters.setDeleteCondition(DeletePolicyCondition.ALL);
564 // send delete request
565 responseMessage.append(sendDeletePolicy(deletePolicyParameters, prop));
566 return responseMessage.toString();
570 * Send delete request to Policy.
572 * @param deletePolicyParameters
573 * The DeletePolicyParameters
575 * The ModelProperties
576 * @return The response message from policy
578 protected String sendDeletePolicy(DeletePolicyParameters deletePolicyParameters, ModelProperties prop) {
579 // Verify whether it is triggered by Validation Test button from UI
580 if (prop.isTestOnly()) {
581 return "delete not executed for test action";
583 // API method to create or update Policy.
584 PolicyChangeResponse response = null;
585 String responseMessage = "";
587 logger.info("Attempting to delete policy...");
588 response = getPolicyEngine().deletePolicy(deletePolicyParameters);
589 responseMessage = response.getResponseMessage();
590 } catch (Exception e) {
591 logger.error("Exception occurred during policy communnication", e);
593 logger.info(LOG_POLICY_PREFIX + responseMessage);
594 if (response != null && response.getResponseCode() == 200) {
595 logger.info("Policy delete successful");
597 logger.warn("Policy delete failed: " + responseMessage);
598 throw new BadRequestException("Policy delete failed: " + responseMessage);
600 return responseMessage;
604 * Create a temp Tosca model file and perform import model to Policy Engine.
606 * @param cldsToscaModel
607 * Policy model details
608 * @return The response message from policy
610 public String importToscaModel(CldsToscaModel cldsToscaModel) {
611 String filePath = "";
613 String clampToscaPath = refProp.getStringValue(TOSCA_FILE_TEMP_PATH);
614 filePath = buildFilePathForToscaFile(clampToscaPath, cldsToscaModel.getToscaModelName());
615 logger.info("Writing Tosca model : " + filePath);
616 Path path = Paths.get(filePath);
617 Files.createDirectories(path.getParent());
618 // Create or Ovewrite an existing the file
619 try (OutputStream out = Files.newOutputStream(path)) {
620 out.write(cldsToscaModel.getToscaModelYaml().getBytes(), 0,
621 cldsToscaModel.getToscaModelYaml().getBytes().length);
623 } catch (IOException e) {
624 logger.error("Exception caught when attempting to write Tosca files to disk", e);
625 throw new PolicyClientException("Exception caught when attempting to write Tosca files to disk", e);
628 ImportParameters importParameters = new ImportParameters();
629 importParameters.setImportParameters(cldsToscaModel.getToscaModelName(), cldsToscaModel.getToscaModelName(),
630 null, filePath, IMPORT_TYPE.MICROSERVICE, String.valueOf(cldsToscaModel.getVersion()));
631 return importModel(importParameters);
636 * @param importParameters
637 * The ImportParameters
638 * @return The response message from policy
640 private String importModel(ImportParameters importParameters) {
641 PolicyChangeResponse response = null;
642 String responseMessage = "";
645 logger.info("Attempting to import tosca policy model for action=" + importParameters.getFilePath());
646 response = getPolicyEngine().policyEngineImport(importParameters);
647 if (response != null) {
648 responseMessage = response.getResponseMessage();
650 } catch (Exception e) {
651 LoggingUtils.setResponseContext("900", "Policy Model import failed", this.getClass().getName());
652 LoggingUtils.setErrorContext("900", "Policy Model import error");
653 logger.error("Exception occurred during policy communication", e);
654 throw new PolicyClientException("Exception while communicating with Policy", e);
656 logger.info(LOG_POLICY_PREFIX + responseMessage);
657 if (response != null && (response.getResponseCode() == 200 || response.getResponseCode() == 204)) {
658 LoggingUtils.setResponseContext("0", "Policy Model import success", this.getClass().getName());
659 logger.info("Policy import model successful");
660 metricsLogger.info("Policy import model success");
662 LoggingUtils.setResponseContext("900", "Policy import model failed", this.getClass().getName());
663 logger.warn("Policy import model failed: " + responseMessage);
664 metricsLogger.info("Policy import model failure");
665 throw new BadRequestException("Policy import model failed: " + responseMessage);
667 return responseMessage;
671 * Build file path for tosca file.
672 * @param clampToscaPath
673 * Temp directory path for writing tosca files
674 * @param toscaModelName
676 * @return File Path on the system
678 private String buildFilePathForToscaFile(String clampToscaPath, String toscaModelName) {
679 return clampToscaPath + "/" + toscaModelName + ".yml";