2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020 AT&T Intellectual Property. All rights
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END============================================
20 * ===================================================================
24 package org.onap.clamp.clds.client;
26 import com.att.eelf.configuration.EELFLogger;
27 import com.att.eelf.configuration.EELFManager;
29 import org.apache.camel.CamelContext;
30 import org.apache.camel.Exchange;
31 import org.apache.camel.builder.ExchangeBuilder;
32 import org.onap.clamp.clds.config.ClampProperties;
33 import org.springframework.beans.factory.annotation.Autowired;
34 import org.springframework.stereotype.Component;
37 * The class implements the communication with the Policy Engine to retrieve
38 * policy models (tosca). It mainly delegates the physical calls to Camel
43 public class PolicyEngineServices {
44 private final CamelContext camelContext;
46 private final ClampProperties refProp;
48 protected static final EELFLogger logger = EELFManager.getInstance().getLogger(PolicyEngineServices.class);
49 protected static final EELFLogger auditLogger = EELFManager.getInstance().getAuditLogger();
50 protected static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger();
51 public static final String POLICY_RETRY_INTERVAL = "policy.retry.interval";
52 public static final String POLICY_RETRY_LIMIT = "policy.retry.limit";
55 public PolicyEngineServices(CamelContext camelContext, ClampProperties refProp) {
56 this.refProp = refProp;
57 this.camelContext = camelContext;
60 private void downloadAllPolicies() {
62 * Exchange myCamelExchange = ExchangeBuilder.anExchange(camelContext)
63 * .withProperty("blueprintResourceId",
64 * resourceUuid).withProperty("blueprintServiceId", serviceUuid)
65 * .withProperty("blueprintName", artifactName).build();
66 * metricsLogger.info("Attempt n°" + i + " to contact DCAE inventory");
68 * Exchange exchangeResponse =
69 * camelContext.createProducerTemplate().send("direct:get-all-policy-models",
75 * This method can be used to download a policy tosca model on the engine.
77 * @param policyType The policy type (id)
78 * @param policyVersion The policy version
79 * @return A string with the whole policy tosca model
80 * @throws InterruptedException in case of issue when sleeping during the retry
82 public String downloadOnePolicy(String policyType, String policyVersion) throws InterruptedException {
83 int retryInterval = 0;
85 if (refProp.getStringValue(POLICY_RETRY_LIMIT) != null) {
86 retryLimit = Integer.valueOf(refProp.getStringValue(POLICY_RETRY_LIMIT));
88 if (refProp.getStringValue(POLICY_RETRY_INTERVAL) != null) {
89 retryInterval = Integer.valueOf(refProp.getStringValue(POLICY_RETRY_INTERVAL));
91 for (int i = 0; i < retryLimit; i++) {
92 Exchange paramExchange = ExchangeBuilder.anExchange(camelContext)
93 .withProperty("policyModelName", policyType).withProperty("policyModelVersion", policyVersion)
96 Exchange exchangeResponse = camelContext.createProducerTemplate().send("direct:get-policy-model",
99 if (Integer.valueOf(200).equals(exchangeResponse.getIn().getHeader("CamelHttpResponseCode"))) {
100 return (String) exchangeResponse.getIn().getBody();
102 logger.info("Policy " + retryInterval + "ms before retrying ...");
103 // wait for a while and try to connect to DCAE again
104 Thread.sleep(retryInterval);