Fix docker uri during filename extraction 33/3133/1
authorSerban Jora <sj2381@att.com>
Wed, 10 Oct 2018 19:04:32 +0000 (15:04 -0400)
committerSerban Jora <sj2381@att.com>
Wed, 10 Oct 2018 19:05:48 +0000 (15:05 -0400)
Change-Id: I226407c700763b29886de75ff480a496145e15d3
Issue-ID: ACUMOS-1780
Signed-off-by: Serban Jora <sj2381@att.com>
gateway/src/main/java/org/acumos/federation/gateway/adapter/PeerGateway.java
gateway/src/main/java/org/acumos/federation/gateway/cds/Artifact.java
gateway/src/main/java/org/acumos/federation/gateway/cds/Reference.java
gateway/src/main/java/org/acumos/federation/gateway/config/InterfaceConfiguration.java
gateway/src/main/java/org/acumos/federation/gateway/controller/CatalogController.java

index 5edc1b8..44335e6 100644 (file)
@@ -20,6 +20,8 @@
 
 package org.acumos.federation.gateway.adapter;
 
+import java.lang.invoke.MethodHandles;
+
 import java.io.Closeable;
 
 import java.util.Collections;
@@ -67,12 +69,13 @@ import org.springframework.core.task.TaskExecutor;
 import org.springframework.stereotype.Component;
 import org.springframework.web.client.HttpStatusCodeException;
 
+
 @Component("peergateway")
 @Scope("singleton")
 @Conditional({GatewayCondition.class})
 public class PeerGateway {
 
-       private final EELFLoggerDelegate log = EELFLoggerDelegate.getLogger(PeerGateway.class);
+       private static final EELFLoggerDelegate log = EELFLoggerDelegate.getLogger(MethodHandles.lookup().lookupClass());
        @Autowired
        private TaskExecutor taskExecutor;
        @Autowired
index 3af4cf1..a22fb9f 100644 (file)
@@ -21,6 +21,10 @@ package org.acumos.federation.gateway.cds;
 
 import org.acumos.cds.domain.MLPArtifact;
 
+import com.fasterxml.jackson.annotation.JsonIgnore;
+
+import com.github.dockerjava.api.model.Identifier;
+
 /**
  */
 public class Artifact extends MLPArtifact
@@ -56,5 +60,15 @@ public class Artifact extends MLPArtifact
                return this.filename;
        }
 
+       @JsonIgnore
+       @Override
+       public String getCanonicalFilename() {
+               if (ArtifactType.DockerImage == ArtifactType.forCode(getArtifactTypeCode())) {
+                       return Identifier.fromCompoundString(getUri()).repository.getPath();
+               }
+               else {
+                       return Reference.super.getCanonicalFilename();
+               }
+       }
 }
 
index 390d5f0..dc88595 100644 (file)
@@ -19,6 +19,8 @@
  */
 package org.acumos.federation.gateway.cds;
 
+import java.lang.invoke.MethodHandles;
+
 import java.net.URI;
 import java.net.URISyntaxException;
 
@@ -26,11 +28,16 @@ import org.apache.commons.io.FilenameUtils;
 
 import com.fasterxml.jackson.annotation.JsonIgnore;
 
+import org.acumos.federation.gateway.config.EELFLoggerDelegate;
+
+
 /**
  * Capable of pointing to some (external) content. Contains the content location as an uri.
  */
 public interface Reference {
 
+       public static final EELFLoggerDelegate log = EELFLoggerDelegate.getLogger(MethodHandles.lookup().lookupClass());
+
        public String getUri();
 
        public void setUri(String theUri);
@@ -61,8 +68,10 @@ public interface Reference {
                                         basename = FilenameUtils.getBaseName(filename),
                                         extension = FilenameUtils.getExtension(filename);
 
-               if (basename.endsWith("-" + getVersion())) {
-                       return basename.substring(0, basename.lastIndexOf('-')) + "." + extension;
+               log.debug(EELFLoggerDelegate.debugLogger, "filename: {}, basename: {}, extension: {}", filename, basename, extension);
+
+               if (basename != null && basename.endsWith("-" + getVersion())) {
+                       return basename.substring(0, basename.lastIndexOf('-')) + (extension != null ? ("." + extension) : "");
                }
                else {
                        return filename;
index 108654c..294d6b2 100644 (file)
@@ -20,6 +20,8 @@
 
 package org.acumos.federation.gateway.config;
 
+import java.lang.invoke.MethodHandles;
+
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.IOException;
@@ -70,7 +72,7 @@ import org.springframework.stereotype.Component;
 @Component
 public class InterfaceConfiguration {
 
-       private final EELFLoggerDelegate log = EELFLoggerDelegate.getLogger(getClass().getName());
+       private static final EELFLoggerDelegate log = EELFLoggerDelegate.getLogger(MethodHandles.lookup().lookupClass());
 
        private String                  address;
        private InetAddress     inetAddress;
index 1edf20c..9ba527f 100644 (file)
@@ -57,8 +57,6 @@ import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.ResponseBody;
 
-import com.github.dockerjava.api.model.Identifier;
-
 import io.swagger.annotations.ApiOperation;
 
 /**