2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 ONAP
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdnc.sli.SliPluginUtils;
25 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
26 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
27 import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
34 * A SvcLogicJavaPlugin that generates DME2 proxy urls using parameters from context memory.
36 public class DME2 implements SvcLogicJavaPlugin {
43 String commonServiceVersion;
46 private static final Logger LOG = LoggerFactory.getLogger(DME2.class);
48 public void setPartner(String partner) {
49 if (partner != null && partner.length() > 0) {
50 this.partner = partner;
54 public DME2(String aafUserName, String aafPassword, String envContext, String routeOffer, String[] proxyUrls, String commonServiceVersion) {
55 this.aafUserName = aafUserName;
56 this.aafPassword = aafPassword;
57 this.envContext = envContext;
58 this.routeOffer = routeOffer;
59 this.proxyUrls = proxyUrls;
61 this.commonServiceVersion = commonServiceVersion;
64 // constructs a URL to contact the proxy which contacts a DME2 service
65 public String constructUrl(String service, String version, String subContext) {
66 StringBuilder sb = new StringBuilder();
68 // The hostname is assigned in a round robin fashion
69 sb.append(acquireHostName());
70 sb.append("/service=" + service);
72 //If the directedGraph passes an explicit version use that, if not use the commonServiceVersion found in the properties file
73 if (version == null) {
74 version = this.commonServiceVersion;
76 sb.append("/version=" + version);
78 sb.append("/envContext=" + this.envContext);
79 if (this.routeOffer != null && this.routeOffer.length() > 0) {
80 sb.append("/routeOffer=" + this.routeOffer);
82 if (subContext != null && subContext.length() > 0) {
83 sb.append("/subContext=" + subContext);
85 sb.append("?dme2.password=" + this.aafPassword);
86 sb.append("&dme2.username=" + this.aafUserName);
87 if (this.partner != null) {
88 sb.append("&dme2.partner=" + this.partner);
90 sb.append("&dme2.allowhttpcode=true");
91 return (sb.toString());
94 public synchronized String acquireHostName() {
95 String retVal = proxyUrls[index];
97 if (index == this.proxyUrls.length) {
104 public void constructUrl(Map<String, String> parameters, SvcLogicContext ctx) throws SvcLogicException {
105 SliPluginUtils.checkParameters(parameters, new String[] { "service", "outputPath" }, LOG);
106 String completeProxyUrl = constructUrl(parameters.get("service"), parameters.get("version"), parameters.get("subContext"));
107 ctx.setAttribute(parameters.get("outputPath"), completeProxyUrl);