update link to upper-constraints.txt
[multicloud/framework.git] / artifactbroker / plugins / forwarding-plugins / src / main / java / org / onap / policy / distribution / forwarding / k8s / K8sArtifactForwarder.java
index e5cf487..b63fea0 100644 (file)
@@ -66,6 +66,7 @@ public class K8sArtifactForwarder implements ArtifactForwarder {
     private static final Logger LOGGER = FlexLogger.getLogger(K8sArtifactForwarder.class);
     private static final String BASE_PATH = "http://localhost:9015/v1/rb/definition";
     private static final String CLOUD_TECHNOLOGY_SPECIFIC_ARTIFACT = "CLOUD_TECHNOLOGY_SPECIFIC_ARTIFACT";
+    private static final String HELM_ARTIFACT = "HELM";
     private Map<String, IArtifactInfo> artifactMap;
 
     private K8sArtifactForwarderParameterGroup configurationParameters = null;
@@ -111,11 +112,12 @@ public class K8sArtifactForwarder implements ArtifactForwarder {
                 .create();
 
             Map<String, Object> map = new LinkedHashMap<String, Object>();
-            map.put("rb-name", vfModule.getVfModuleModelName());
-            map.put("rb-version", vfModule.getVfModuleModelVersion());
+            map.put("rb-name", vfModule.getVfModuleModelInvariantUUID());
+            map.put("rb-version", vfModule.getVfModuleModelCustomizationUUID());
             map.put("descritpion",vfModule.getVfModuleModelDescription());
             Map<String, String> labelMap = new LinkedHashMap<String, String>();
-            labelMap.put("vnf_customization_uuid",vfModule.getVfModuleModelCustomizationUUID());
+            labelMap.put("vf_module_model_uuid",vfModule.getVfModuleModelUUID());
+            labelMap.put("vf_module_model_name",vfModule.getVfModuleModelName());
             map.put("labels", labelMap);
             String json = gson.toJson(map);
 
@@ -130,32 +132,70 @@ public class K8sArtifactForwarder implements ArtifactForwarder {
     }
 
     private boolean uploadArtifact(VfModuleModel vfModule) {
-        String url = BASE_PATH + "/" + vfModule.getVfModuleModelName() + "/"
-            + vfModule.getVfModuleModelVersion() + "/content";
+        String url = BASE_PATH + "/" + vfModule.getVfModuleModelInvariantUUID() + "/"
+            + vfModule.getVfModuleModelCustomizationUUID() + "/content";
         HttpPost httpPost = new HttpPost(url);
         httpPost.addHeader("content-type", "application/x-www-form-urlencoded;charset=utf-8");
 
         List<String> artifacts = vfModule.getArtifacts();
         System.out.println("artifacts = " + artifacts);
 
-        String cloudUuid = null;
+        String vfNamePrefix = vfModule.getVfModuleModelName().toLowerCase();
+        if ( vfNamePrefix.indexOf("..") > 0 ) {
+            vfNamePrefix = vfNamePrefix.substring(vfNamePrefix.indexOf("..") + 2);
+            if ( vfNamePrefix.indexOf("..") > 0 )
+                vfNamePrefix = vfNamePrefix.substring(0, vfNamePrefix.indexOf("..")) + "_";
+            else
+                vfNamePrefix = "";
+        } else
+            vfNamePrefix = "";
+
         IArtifactInfo cloudArtifact = null;
+        IArtifactInfo firstCloudArtifact = null;
+        int cloudArtifactCount = 0;
         boolean found = false;
 
         for (String artifact: artifacts) {
-            if ( artifactMap.get(artifact) != null
-                && artifactMap.get(artifact).getArtifactType().equals("CLOUD_TECHNOLOGY_SPECIFIC_ARTIFACT")) {
-                cloudArtifact = artifactMap.get(artifact);
-                cloudUuid = cloudArtifact.getArtifactUUID();
+            if (artifactMap.get(artifact) != null
+                    && artifactMap.get(artifact).getArtifactType().equals(HELM_ARTIFACT)) {
+                firstCloudArtifact = artifactMap.get(artifact);
+                cloudArtifact = firstCloudArtifact;
+                cloudArtifactCount = 1;
                 found = true;
                 break;
             }
         }
 
-        if ( found == false ) {
-            System.out.println(" meets error , no CLOUD_TECHNOLOGY_SPECIFIC_ARTIFACT type found ");
-            return false;
+        if ( found == false  )
+            for (String artifact: artifacts) {
+                if ( artifactMap.get(artifact) != null
+                    && artifactMap.get(artifact).getArtifactType().equals(CLOUD_TECHNOLOGY_SPECIFIC_ARTIFACT)) {
+                    if ( cloudArtifactCount == 0 )
+                        firstCloudArtifact = artifactMap.get(artifact);
+                    cloudArtifactCount++;
+                    IArtifactInfo tmpArtifact = artifactMap.get(artifact);
+                    if ( tmpArtifact.getArtifactName().toLowerCase().startsWith(vfNamePrefix) ) {
+                        cloudArtifact = tmpArtifact;
+                        found = true;
+                        break;
+                    }
+                }
+            }
+
+        if ( found == false  ) {
+            if ( firstCloudArtifact == null ) {
+                System.out.println(" meets error , no CLOUD_TECHNOLOGY_SPECIFIC_ARTIFACT or HELM type found ");
+                return false;
+            } else {
+                if ( cloudArtifactCount == 1 || vfNamePrefix == "" ) {
+                    cloudArtifact = firstCloudArtifact;
+                } else {
+                    System.out.println(" meets error , CLOUD_TECHNOLOGY_SPECIFIC_ARTIFACT artifacts mismatch ");
+                    return false;
+                }
+            }
         }
+
         String cloudArtifactPath = "/data/" + vfModule.getVfModuleModelCustomizationUUID()
             + "/" + cloudArtifact.getArtifactName();
         File file = new File(cloudArtifactPath);