2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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=========================================================
22 package org.openecomp.sdnc.sli.SliPluginUtils;
26 import org.openecomp.sdnc.sli.SvcLogicContext;
27 import org.openecomp.sdnc.sli.SvcLogicException;
28 import org.openecomp.sdnc.sli.SvcLogicJavaPlugin;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
35 * A SvcLogicJavaPlugin that generates DME2 proxy urls using parameters from context memory.
37 public class DME2 implements SvcLogicJavaPlugin {
44 String commonServiceVersion;
47 private static final Logger LOG = LoggerFactory.getLogger(DME2.class);
49 public void setPartner(String partner) {
50 if (partner != null && partner.length() > 0) {
51 this.partner = partner;
55 public DME2(String aafUserName, String aafPassword, String envContext, String routeOffer, String[] proxyUrls, String commonServiceVersion) {
56 this.aafUserName = aafUserName;
57 this.aafPassword = aafPassword;
58 this.envContext = envContext;
59 this.routeOffer = routeOffer;
60 this.proxyUrls = proxyUrls;
62 this.commonServiceVersion = commonServiceVersion;
65 // constructs a URL to contact the proxy which contacts a DME2 service
66 public String constructUrl(String service, String version, String subContext) {
67 StringBuilder sb = new StringBuilder();
69 // The hostname is assigned in a round robin fashion
70 sb.append(acquireHostName());
71 sb.append("/service=" + service);
73 //If the directedGraph passes an explicit version use that, if not use the commonServiceVersion found in the properties file
74 if (version == null) {
75 version = this.commonServiceVersion;
77 sb.append("/version=" + version);
79 sb.append("/envContext=" + this.envContext);
80 if (this.routeOffer != null && this.routeOffer.length() > 0) {
81 sb.append("/routeOffer=" + this.routeOffer);
83 if (subContext != null && subContext.length() > 0) {
84 sb.append("/subContext=" + subContext);
86 sb.append("?dme2.password=" + this.aafPassword);
87 sb.append("&dme2.username=" + this.aafUserName);
88 if (this.partner != null) {
89 sb.append("&dme2.partner=" + this.partner);
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);