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=d920907120d3d89a634f3a1b2b09886f11df7e15;hb=f1f52b3ccf0ab78007a98947211b4fcdfd54b5e6;hpb=ef9c71ab1efce6e60eb5d8c89cf09c5182c48730 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 d920907..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 @@ -64,24 +64,24 @@ import org.onap.sdc.api.notification.IArtifactInfo; public class K8sArtifactForwarder implements ArtifactForwarder { private static final Logger LOGGER = FlexLogger.getLogger(K8sArtifactForwarder.class); - private static final String BASE_PATH = "http://localhost:8081/v1/rb/definition"; + 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 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,29 +198,31 @@ 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()); - if ( closeableHttpResponse.getStatusLine().getStatusCode() != 200 ) { - System.out.println("exception: ret= " + closeableHttpResponse.getStatusLine().getStatusCode()); - } else { + int status = closeableHttpResponse.getStatusLine().getStatusCode(); + // [200, 300] means pass + if ( (status >=200) && (status <= 300) ) { ret = true; + } else { + System.out.println("exception: ret= " + status); } 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); } }