Skip to content

Commit

Permalink
Merge pull request #136 from cloudsoft/tosca-embedded-resources
Browse files Browse the repository at this point in the history
Added failing test for tosca-embedded-resources
  • Loading branch information
ahgittin authored Aug 22, 2019
2 parents 472f61e + 39bf8bd commit 86fa3e8
Show file tree
Hide file tree
Showing 13 changed files with 101 additions and 10 deletions.
31 changes: 31 additions & 0 deletions brooklyn-tosca-transformer/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -164,4 +164,35 @@
<version>${spring.version}</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<versionRange>[2.17,)</versionRange>
<goals>
<goal>check</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;

import alien4cloud.model.components.Csar;
import alien4cloud.model.topology.AbstractPolicy;
import alien4cloud.model.topology.GenericPolicy;
import alien4cloud.model.topology.NodeGroup;
Expand All @@ -31,11 +32,15 @@ public class Alien4CloudApplication implements ToscaApplication {
private final String name;
private final Topology deploymentTopology;
private final String deploymentId;
// the class ArchivePostProcessor does not correctly set impl artifact on things in topologies (eg interfaces);
// so let's _us_ maintain it as well
private final Csar archive;

public Alien4CloudApplication(String name, Topology deploymentTopology, String deploymentId) {
public Alien4CloudApplication(String name, Topology deploymentTopology, String deploymentId, Csar archive) {
this.name = name;
this.deploymentTopology = deploymentTopology;
this.deploymentId = deploymentId;
this.archive = archive;
}

@Override
Expand All @@ -62,6 +67,10 @@ public Topology getTopology() {
return deploymentTopology;
}

public Csar getArchive() {
return archive;
}

private Map<String, NodeTemplate> getNodeTemplates(){
return ImmutableMap.copyOf(getTopology().getNodeTemplates());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.apache.brooklyn.util.collections.MutableMap;
import org.apache.brooklyn.util.collections.MutableSet;
import org.apache.brooklyn.util.core.ResourceUtils;
import org.apache.brooklyn.util.net.Urls;
import org.apache.brooklyn.util.os.Os;
import org.apache.brooklyn.util.text.Strings;
import org.slf4j.Logger;
Expand Down Expand Up @@ -547,14 +548,15 @@ public Optional<Path> getArtifactPath(String nodeId, Alien4CloudApplication tosc
}

private Alien4CloudApplication newToscaApplication(Csar csar) {
return new Alien4CloudApplication(csar.getName(), getTopologyOfCsar(csar), "");
return new Alien4CloudApplication(csar.getName(), getTopologyOfCsar(csar), "", csar);
}

@Override
public Alien4CloudApplication newToscaApplication(String id) {
DeploymentTopology deploymentTopology = deploymentTopologyService.getOrFail(id);
Application application = applicationService.getOrFail(deploymentTopology.getDelegateId());
return new Alien4CloudApplication(application.getName(), deploymentTopology, id);
return new Alien4CloudApplication(application.getName(), deploymentTopology, id,
null /* TODO is there a way to find the containing CSAR; will things in topologies in here break without it? */);
}

@Override
Expand Down Expand Up @@ -616,11 +618,43 @@ protected String getScript(ImplementationArtifact artifact) {
// Trying to get the CSAR file based on the artifact reference. If it fails, then we try to get the
// content of the script from any resources
String artifactRef = artifact.getArtifactRef();
Optional<Path> csarPath = getCsarPath(artifact.getArchiveName(), artifact.getArchiveVersion());
if(!csarPath.isPresent()) {
String proto = Urls.getProtocol(artifactRef);
if ("classpath".equals(proto)) {
proto = null;
artifactRef = Strings.removeAllFromStart(artifactRef, "classpath:", "/");
// recast classpath URLs as things within the CSAR
}
Optional<Path> csarPath = Optional.absent();

if (proto==null) {
// not a URL; look in archive

csarPath = getCsarPath(artifact.getArchiveName(), artifact.getArchiveVersion());
if (!csarPath.isPresent() && toscaApplication.getArchive()!=null) {
// archive name / version are null in some cases, because the ArchivePostProcessor doesn't
// properly initialize ImplArts _inside_ topologies. we record the archive on the app
// but in _some_ call paths only
csarPath = getCsarPath(toscaApplication.getArchive().getName(), toscaApplication.getArchive().getVersion());
}
if (csarPath.isPresent()) {
if (new File(csarPath.get().getParent().toString() + expandedFolder + artifactRef).exists()) {
return new ResourceUtils(this).getResourceAsString(csarPath.get().getParent().toString() + expandedFolder + artifactRef);
}
}
}
// the brooklyn entity's bundle may also be a valid search path;
// ideally build up a search path including the folder above if found
// (if reading a tosca yaml then it would be valid not to have one however,
// so could remove the above error eg if it's a tosca yaml in a brooklyn bundle),
// and in the call below use that search sequence
try {
return new ResourceUtils(this).getResourceAsString(artifactRef);
} catch (RuntimeException e) {
LOG.warn("Could not find "+artifactRef+" (rethrowing); "+
(csarPath.isPresent() ? "csar found as "+csarPath : proto==null ? "csar not found" : "context not set")
+": "+e);
throw e;
}
return new ResourceUtils(this).getResourceAsString(csarPath.get().getParent().toString() + expandedFolder + artifactRef);
}

protected Optional<Object> buildExportStatements(Operation op, String script) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ public ParsingResult<Csar> parse(String plan, BrooklynClassLoadingContext contex
throw Exceptions.propagate(e);
}
}
// TODO either we need to be able to look up the CSAR ZIP after upload, or
// we have to annotate it with context and csarLink of this file
tp = uploader.uploadArchive(resourceFromUrl, "submitted-tosca-archive");

} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class Alien4CloudApplicationTest {
@BeforeMethod(alwaysRun = true)
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
alien4CloudApplication = new Alien4CloudApplication("TestApplication", deploymentTopology, "testDeployment");
alien4CloudApplication = new Alien4CloudApplication("TestApplication", deploymentTopology, "testDeployment", null);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import org.apache.brooklyn.api.entity.Entity;
import org.apache.brooklyn.api.entity.EntitySpec;
import org.apache.brooklyn.api.location.LocationSpec;
import org.apache.brooklyn.api.location.PortRange;
import org.apache.brooklyn.api.policy.PolicySpec;
import org.apache.brooklyn.camp.brooklyn.spi.dsl.BrooklynDslDeferredSupplier;
import org.apache.brooklyn.core.config.ConfigKeys;
Expand Down Expand Up @@ -515,7 +514,21 @@ public void testChainedRelations() throws Exception {

@Test
public void testCsarLink() throws Exception {
EntitySpec<? extends Application> app = create("classpath://templates/csar-link-1.yaml");
EntitySpec<? extends Application> app = create("classpath://templates/csar-link-external-url.yaml");
assertNotNull(app);
assertEquals(app.getChildren().size(), 1);
}

@Test
public void testCsarLinkWithEmbeddedResourcesUsingClasspathUrl() throws Exception {
EntitySpec<? extends Application> app = create("classpath://templates/csar-link-classpath-url.yaml");
assertNotNull(app);
assertEquals(app.getChildren().size(), 1);
}

@Test
public void testCsarLinkWithEmbeddedResourcesAsPaths() throws Exception {
EntitySpec<? extends Application> app = create("classpath://templates/csar-link-path.yaml");
assertNotNull(app);
assertEquals(app.getChildren().size(), 1);
}
Expand Down
Binary file not shown.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
csar_link: classpath://templates/csar-classpath-url.zip
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
csar_link: classpath://templates/csar-external-url.zip
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
csar_link: classpath://templates/csar-path.zip
Binary file not shown.

0 comments on commit 86fa3e8

Please sign in to comment.