X-Git-Url: https://gerrit.onap.org/r/gitweb?p=multicloud%2Fframework.git;a=blobdiff_plain;f=artifactbroker%2Fplugins%2Fforwarding-plugins%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fpolicy%2Fdistribution%2Fforwarding%2Fk8s%2FK8sArtifactForwarder.java;h=8ad07df4a0b9c60e64c8994ed06cb42415db77d5;hp=9bfe2641cca0167f5a494268a921d3ff5077eef8;hb=f1f52b3ccf0ab78007a98947211b4fcdfd54b5e6;hpb=79f626b0c4419dfcb5b7d1ea0a279a523c6c21bd diff --git a/artifactbroker/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/k8s/K8sArtifactForwarder.java b/artifactbroker/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/k8s/K8sArtifactForwarder.java index 9bfe264..8ad07df 100644 --- a/artifactbroker/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/k8s/K8sArtifactForwarder.java +++ b/artifactbroker/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/k8s/K8sArtifactForwarder.java @@ -69,19 +69,19 @@ public class K8sArtifactForwarder implements ArtifactForwarder { private Map artifactMap; private K8sArtifactForwarderParameterGroup configurationParameters = null; - + @Override public void forward(PolicyInput policyInput) { if (policyInput instanceof CloudArtifact) { - System.out.println("get a CloudArtifact !"); + System.out.println("get a CloudArtifact !"); CloudArtifact cloudArtifact = (CloudArtifact) policyInput; artifactMap = cloudArtifact.getArtifactTypeMap(); - System.out.println("the artifactMap = " + artifactMap); + System.out.println("the artifactMap = " + artifactMap); ArrayList vfModuleModels = cloudArtifact.getVfModulePayload(); - System.out.println("the size of vfModule = " + vfModuleModels.size()); - + System.out.println("the size of vfModule = " + vfModuleModels.size()); + for (VfModuleModel vfModule : vfModuleModels) { forwardAndUpload(vfModule); } @@ -92,7 +92,7 @@ public class K8sArtifactForwarder implements ArtifactForwarder { } private void forwardAndUpload(VfModuleModel vfModule) { - + System.out.println("before create type !"); boolean definitionCreated = createDefinition(vfModule); System.out.println(" after create type !"); @@ -111,8 +111,8 @@ public class K8sArtifactForwarder implements ArtifactForwarder { .create(); Map map = new LinkedHashMap(); - map.put("rb-name", vfModule.getVfModuleModelName()); - map.put("rb-version", vfModule.getVfModuleModelVersion()); + map.put("rb-name", vfModule.getVfModuleModelInvariantUUID()); + map.put("rb-version", vfModule.getVfModuleModelUUID()); map.put("descritpion",vfModule.getVfModuleModelDescription()); Map labelMap = new LinkedHashMap(); labelMap.put("vnf_customization_uuid",vfModule.getVfModuleModelCustomizationUUID()); @@ -130,38 +130,64 @@ 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.getVfModuleModelUUID() + "/content"; HttpPost httpPost = new HttpPost(url); httpPost.addHeader("content-type", "application/x-www-form-urlencoded;charset=utf-8"); List 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 + if ( artifactMap.get(artifact) != null && artifactMap.get(artifact).getArtifactType().equals("CLOUD_TECHNOLOGY_SPECIFIC_ARTIFACT")) { - cloudArtifact = artifactMap.get(artifact); - cloudUuid = cloudArtifact.getArtifactUUID(); - found = true; - break; + 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 ) { - System.out.println(" meets error , no CLOUD_TECHNOLOGY_SPECIFIC_ARTIFACT type found "); - return false; + + if ( found == false ) { + if ( firstCloudArtifact == null ) { + System.out.println(" meets error , no CLOUD_TECHNOLOGY_SPECIFIC_ARTIFACT 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() + + String cloudArtifactPath = "/data/" + vfModule.getVfModuleModelCustomizationUUID() + "/" + cloudArtifact.getArtifactName(); File file = new File(cloudArtifactPath); FileEntity entity = new FileEntity(file); httpPost.setEntity(entity); - + return invokeHttpPost("uploading", httpPost); } @@ -172,15 +198,15 @@ public class K8sArtifactForwarder implements ArtifactForwarder { } protected static boolean invokeHttpPost(String action, HttpPost httpPost) { - System.out.println("httpPost begin!"); + System.out.println("httpPost URI: " + httpPost); boolean ret = false; String errorMsg; label1: { try ( CloseableHttpClient httpClient = HttpClients.createDefault() ) { - System.out.println("result1") ; + System.out.println("Execute Post Body: " + EntityUtils.toString(httpPost.getEntity())); CloseableHttpResponse closeableHttpResponse = httpClient.execute(httpPost); - System.out.println("result2") ; + System.out.println("result2"); String result = EntityUtils.toString(closeableHttpResponse.getEntity()); System.out.println("result = {}" + result); System.out.println("status = {}" + closeableHttpResponse.getStatusLine().getStatusCode()); @@ -194,9 +220,9 @@ public class K8sArtifactForwarder implements ArtifactForwarder { closeableHttpResponse.close(); break label1; - } catch (IOException var) { - errorMsg = action + ":httpPostWithJSON connect faild"; - System.out.println("exception: POST_CONNECT_FAILD : {}" + errorMsg); + } catch (IOException exp) { + errorMsg = action + " :invokeHttpPost failed with: " + exp.getMessage(); + System.out.println("exception: POST FAILED : {}" + errorMsg); } }