* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END============================================
+ * Modifications copyright (c) 2019 AT&T
* ===================================================================
*
*/
+
package org.onap.clamp.clds.sdc.controller.installer;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
+
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
+
import org.json.JSONObject;
import org.springframework.stereotype.Component;
import org.yaml.snakeyaml.Yaml;
private static final String TYPE = "type";
private static final String PROPERTIES = "properties";
private static final String NAME = "name";
+ private static final String POLICYID = "policy_id";
+ private static final String POLICY_TYPEID = "policy_type_id";
private static final String RELATIONSHIPS = "relationships";
private static final String CLAMP_NODE_RELATIONSHIPS_GETS_INPUT_FROM = "clamp_node.relationships.gets_input_from";
private static final String TARGET = "target";
- BlueprintParser() {}
-
- Set<MicroService> getMicroServices(String blueprintString) {
- Set <MicroService> microServices = new HashSet<>();
+ public Set<MicroService> getMicroServices(String blueprintString) {
+ Set<MicroService> microServices = new HashSet<>();
JsonObject jsonObject = BlueprintParser.convertToJson(blueprintString);
JsonObject results = jsonObject.get(NODE_TEMPLATES).getAsJsonObject();
return microServices;
}
- List<MicroService> fallbackToOneMicroService(String blueprintString) {
+ public List<MicroService> fallbackToOneMicroService(String blueprintString) {
JsonObject jsonObject = BlueprintParser.convertToJson(blueprintString);
JsonObject results = jsonObject.get(NODE_TEMPLATES).getAsJsonObject();
String theBiggestMicroServiceContent = "";
String theBiggestMicroServiceKey = "";
for (Entry<String, JsonElement> entry : results.entrySet()) {
String msAsString = entry.getValue().toString();
- int len =msAsString.length();
- if(len > theBiggestMicroServiceContent.length()) {
+ int len = msAsString.length();
+ if (len > theBiggestMicroServiceContent.length()) {
theBiggestMicroServiceContent = msAsString;
theBiggestMicroServiceKey = entry.getKey();
}
}
String msName = theBiggestMicroServiceKey.toLowerCase().contains(HOLMES_PREFIX) ? HOLMES : TCA;
- return Collections.singletonList(new MicroService(msName, ""));
+ return Collections
+ .singletonList(new MicroService(msName, "onap.policy.monitoring.cdap.tca.hi.lo.app", "", "", ""));
}
String getName(Entry<String, JsonElement> entry) {
JsonArray relationships = ob.getAsJsonArray(RELATIONSHIPS);
for (JsonElement element : relationships) {
String target = getTarget(element.getAsJsonObject());
- if(!target.isEmpty()) {
+ if (!target.isEmpty()) {
return target;
}
}
return "";
}
+ String getModelType(Entry<String, JsonElement> entry) {
+ JsonObject ob = entry.getValue().getAsJsonObject();
+ if (ob.has(PROPERTIES)) {
+ JsonObject properties = ob.get(PROPERTIES).getAsJsonObject();
+ if (properties.has(POLICYID)) {
+ JsonObject policyIdObj = properties.get(POLICYID).getAsJsonObject();
+ if (policyIdObj.has(POLICY_TYPEID)) {
+ return policyIdObj.get(POLICY_TYPEID).getAsString();
+ }
+ }
+ }
+ return "";
+ }
+
+ String getBlueprintName(Entry<String, JsonElement> entry) {
+ return entry.getKey();
+ }
+
MicroService getNodeRepresentation(Entry<String, JsonElement> entry) {
String name = getName(entry);
String getInputFrom = getInput(entry);
- return new MicroService(name, getInputFrom);
+ String modelType = getModelType(entry);
+ String blueprintName = getBlueprintName(entry);
+ return new MicroService(name, modelType, getInputFrom, "", blueprintName);
}
private String getTarget(JsonObject elementObject) {
- if (elementObject.has(TYPE) &&
- elementObject.has(TARGET) &&
- elementObject.get(TYPE).getAsString().equals(CLAMP_NODE_RELATIONSHIPS_GETS_INPUT_FROM)) {
+ if (elementObject.has(TYPE) && elementObject.has(TARGET)
+ && elementObject.get(TYPE).getAsString().equals(CLAMP_NODE_RELATIONSHIPS_GETS_INPUT_FROM)) {
return elementObject.get(TARGET).getAsString();
}
return "";