Merge "save csar file path add directory version"
authorSeshu Kumar M <seshu.kumar.m@huawei.com>
Tue, 18 Sep 2018 06:18:31 +0000 (06:18 +0000)
committerGerrit Code Review <gerrit@onap.org>
Tue, 18 Sep 2018 06:18:31 +0000 (06:18 +0000)
1  2 
asdc-controller/src/main/java/org/onap/so/asdc/client/ASDCController.java
bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/resource/ResourceRequestBuilder.java

@@@ -22,6 -22,7 +22,7 @@@ d * ============LICENSE_START==========
  package org.onap.so.asdc.client;
  
  
+ import java.io.File;
  import java.io.FileOutputStream;
  import java.io.IOException;
  import java.io.UnsupportedEncodingException;
@@@ -268,7 -269,7 +269,7 @@@ public class ASDCController 
  
     
  
 -    private IDistributionClientDownloadResult downloadTheArtifact (IArtifactInfo artifact,
 +    protected IDistributionClientDownloadResult downloadTheArtifact (IArtifactInfo artifact,
                                                                     String distributionId) throws ASDCDownloadException {
  
          LOGGER.debug ("Trying to download the artifact : " + artifact.getArtifactURL ()
                        + artifact.getArtifactUUID ()
                        + ")");
        
+       String filePath = System.getProperty("mso.config.path") + "/ASDC" + "/" + artifact.getArtifactVersion() + "/" + artifact.getArtifactName();
+       // make parent directory
+       File file = new File(filePath);         
+       File fileParent = file.getParentFile();
+       if (!fileParent.exists()) {
+           fileParent.mkdirs();
+       }
        byte[] payloadBytes = resultArtifact.getArtifactPayload();
        
-       try (FileOutputStream outFile = new FileOutputStream(System.getProperty("mso.config.path") + "/ASDC" + "/" + artifact.getArtifactName())) {
+       try (FileOutputStream outFile = new FileOutputStream(filePath)) {
                LOGGER.info(MessageEnum.ASDC_RECEIVE_SERVICE_NOTIF, "***WRITE FILE ARTIFACT NAME", "ASDC", artifact.getArtifactName());
                outFile.write(payloadBytes, 0, payloadBytes.length);
                outFile.close();
      }
  
  
 -    private void sendDeployNotificationsForResource(VfResourceStructure vfResourceStructure,DistributionStatusEnum distribStatus, String errorReason) {
 +    protected void sendDeployNotificationsForResource(VfResourceStructure vfResourceStructure,DistributionStatusEnum distribStatus, String errorReason) {
  
        for (IArtifactInfo artifactInfo : vfResourceStructure.getResourceInstance().getArtifacts()) {
  
        }
      }
      
 -    private void sendCsarDeployNotification(INotificationData iNotif, VfResourceStructure resourceStructure, ToscaResourceStructure toscaResourceStructure, boolean deploySuccessful, String errorReason) {
 +    protected void sendCsarDeployNotification(INotificationData iNotif, VfResourceStructure resourceStructure, ToscaResourceStructure toscaResourceStructure, boolean deploySuccessful, String errorReason) {
        
                IArtifactInfo csarArtifact = toscaResourceStructure.getToscaArtifact();
                
                }
      }
      
 -    private void deployResourceStructure (VfResourceStructure resourceStructure, ToscaResourceStructure toscaResourceStructure) throws ArtifactInstallerException {
 +    protected void deployResourceStructure (VfResourceStructure resourceStructure, ToscaResourceStructure toscaResourceStructure) throws ArtifactInstallerException {
  
        LOGGER.info (MessageEnum.ASDC_START_DEPLOY_ARTIFACT, resourceStructure.getResourceInstance().getResourceInstanceName(), resourceStructure.getResourceInstance().getResourceUUID(), "ASDC");
          try {
        DOWNLOAD, DEPLOY
      }
  
 -    private void sendASDCNotification (NotificationType notificationType,
 +    protected void sendASDCNotification (NotificationType notificationType,
                                         String artifactURL,
                                         String consumerID,
                                         String distributionID,
          LOGGER.recordMetricEvent (subStarttime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully sent notification to ASDC", "ASDC", action, null);
      }
      
 -    private void sendFinalDistributionStatus (
 +    protected void sendFinalDistributionStatus (
                String distributionID,
                DistributionStatusEnum status,
                String errorReason) {
          }
      }
  
 -    private void processResourceNotification (INotificationData iNotif) {
 +    protected void processResourceNotification (INotificationData iNotif) {
        // For each artifact, create a structure describing the VFModule in a ordered flat level
        VfResourceStructure resourceStructure = null;
        ToscaResourceStructure toscaResourceStructure = new ToscaResourceStructure();
                                "Exception caught during Installation of artifact", "ASDC", "processResourceNotification", MsoLogger.ErrorCode.BusinessProcesssError, "Exception in processResourceNotification", e);
        }
      }
 -    private void processCsarServiceArtifacts (INotificationData iNotif, ToscaResourceStructure toscaResourceStructure) {
 +    protected void processCsarServiceArtifacts (INotificationData iNotif, ToscaResourceStructure toscaResourceStructure) {
        
        List<IArtifactInfo> serviceArtifacts = iNotif.getServiceArtifacts();
        
      }
      
      private static final String UNKNOWN="Unknown";
 -
 +    
      /**
       * @return the address of the ASDC we are connected to.
       */
@@@ -55,9 -55,9 +55,9 @@@ import com.google.gson.reflect.TypeToke
  
  public class ResourceRequestBuilder {
  
 -    public static String CUSTOMIZATION_UUID = "customizationUUID";
 +    private static String CUSTOMIZATION_UUID = "customizationUUID";
  
 -    public static String SERVICE_URL_TOSCA_CSAR = "/v3/serviceToscaCsar?serviceModelUuid=";
 +    private static String SERVICE_URL_TOSCA_CSAR = "/v3/serviceToscaCsar";
  
      private static MsoLogger LOGGER = MsoLogger.getMsoLogger(MsoLogger.Catalog.RA, ResourceRequestBuilder.class);
  
  
      private static String getCsarFromUuid(String uuid) throws Exception {
                String catalogEndPoint = UrnPropertiesReader.getVariable("mso.catalog.db.endpoint");
 -      HttpClient client = new HttpClient(UriBuilder.fromUri(catalogEndPoint + SERVICE_URL_TOSCA_CSAR + uuid).build().toURL(), "application/json", TargetEntity.CATALOG_DB);
 +      HttpClient client = new HttpClient(UriBuilder.fromUri(catalogEndPoint).path(SERVICE_URL_TOSCA_CSAR).queryParam("serviceModelUuid", uuid).build().toURL(), "application/json", TargetEntity.CATALOG_DB);
        
          Response response = client.get();
          String value = response.readEntity(String.class);
  
          HashMap<String, String> map = new Gson().fromJson(value, new TypeToken<HashMap<String, String>>() {}.getType());
  
-         File csarFile = new File(System.getProperty("mso.config.path") + "ASDC/" + map.get("name"));
+         String filePath = System.getProperty("mso.config.path") + "ASDC/" +  map.get("version") + "/" + map.get("name");
+         File csarFile = new File(filePath);
  
          if(!csarFile.exists()) {
              throw new Exception("csar file does not exist.");