Search in sources :

Example 6 with PublishArtifactResponse

use of com.thoughtworks.go.plugin.access.artifact.model.PublishArtifactResponse in project gocd by gocd.

the class ArtifactsPublisherTest method shouldDeletePluggableArtifactMetadataDirectory.

@Test
public void shouldDeletePluggableArtifactMetadataDirectory() throws Exception {
    TestFileUtil.createTestFile(workingFolder, "installer.zip");
    TestFileUtil.createTestFile(workingFolder, "testreports.xml");
    final ArtifactStore artifactStore = new ArtifactStore("s3", "cd.go.s3", create("Foo", false, "Bar"));
    final ArtifactStores artifactStores = new ArtifactStores(artifactStore);
    final ArtifactPlan artifactPlan = new ArtifactPlan(new PluggableArtifactConfig("installers", "s3", create("Baz", true, "Car")));
    List<ArtifactPlan> artifactPlans = Arrays.asList(new ArtifactPlan(ArtifactPlanType.file, "installer.zip", "dist"), new ArtifactPlan(ArtifactPlanType.unit, "testreports.xml", "testreports"), artifactPlan);
    when(artifactExtension.publishArtifact(eq("cd.go.s3"), eq(artifactPlan), eq(artifactStore), anyString(), eq(env))).thenReturn(new PublishArtifactResponse(Collections.singletonMap("Foo", "Bar")));
    final GoPublisher publisher = mock(GoPublisher.class);
    assertThat(Arrays.asList(workingFolder.list()), containsInAnyOrder("testreports.xml", "installer.zip", "cruise-output"));
    new ArtifactsPublisher(publisher, artifactExtension, artifactStores, registry, workingFolder).publishArtifacts(artifactPlans, env);
    assertThat(Arrays.asList(workingFolder.list()), containsInAnyOrder("testreports.xml", "installer.zip", "cruise-output"));
}
Also used : PluggableArtifactConfig(com.thoughtworks.go.config.PluggableArtifactConfig) ArtifactStores(com.thoughtworks.go.config.ArtifactStores) ArtifactStore(com.thoughtworks.go.config.ArtifactStore) PublishArtifactResponse(com.thoughtworks.go.plugin.access.artifact.model.PublishArtifactResponse) GoPublisher(com.thoughtworks.go.work.GoPublisher) Test(org.junit.jupiter.api.Test)

Example 7 with PublishArtifactResponse

use of com.thoughtworks.go.plugin.access.artifact.model.PublishArtifactResponse in project gocd by gocd.

the class ArtifactsPublisherTest method shouldAddPluggableArtifactMetadataFileArtifactPlanAtTop.

@Test
public void shouldAddPluggableArtifactMetadataFileArtifactPlanAtTop() throws Exception {
    TestFileUtil.createTestFile(workingFolder, "installer.zip");
    TestFileUtil.createTestFile(workingFolder, "testreports.xml");
    final ArtifactStore artifactStore = new ArtifactStore("s3", "cd.go.s3", create("Foo", false, "Bar"));
    final ArtifactStores artifactStores = new ArtifactStores(artifactStore);
    final ArtifactPlan artifactPlan = new ArtifactPlan(new PluggableArtifactConfig("installers", "s3", create("Baz", true, "Car")));
    List<ArtifactPlan> artifactPlans = Arrays.asList(new ArtifactPlan(ArtifactPlanType.file, "installer.zip", "dist"), new ArtifactPlan(ArtifactPlanType.unit, "testreports.xml", "testreports"), artifactPlan);
    when(artifactExtension.publishArtifact(eq("cd.go.s3"), eq(artifactPlan), eq(artifactStore), anyString(), eq(env))).thenReturn(new PublishArtifactResponse(Collections.singletonMap("Foo", "Bar")));
    final GoPublisher publisher = mock(GoPublisher.class);
    new ArtifactsPublisher(publisher, artifactExtension, artifactStores, registry, workingFolder).publishArtifacts(artifactPlans, env);
    InOrder inOrder = inOrder(publisher);
    inOrder.verify(publisher).upload(any(), eq("pluggable-artifact-metadata"));
    inOrder.verify(publisher).upload(any(), eq("dist"));
    inOrder.verify(publisher).upload(any(), eq("testreports"));
}
Also used : PluggableArtifactConfig(com.thoughtworks.go.config.PluggableArtifactConfig) ArtifactStores(com.thoughtworks.go.config.ArtifactStores) InOrder(org.mockito.InOrder) ArtifactStore(com.thoughtworks.go.config.ArtifactStore) PublishArtifactResponse(com.thoughtworks.go.plugin.access.artifact.model.PublishArtifactResponse) GoPublisher(com.thoughtworks.go.work.GoPublisher) Test(org.junit.jupiter.api.Test)

Example 8 with PublishArtifactResponse

use of com.thoughtworks.go.plugin.access.artifact.model.PublishArtifactResponse in project gocd by gocd.

the class ArtifactsPublisher method publishPluggableArtifact.

private void publishPluggableArtifact(PluggableArtifactMetadata pluggableArtifactMetadata, ArtifactPlan artifactPlan, ArtifactStore artifactStore, EnvironmentVariableContext environmentVariableContext) {
    try {
        final String pluginId = artifactStore.getPluginId();
        final String message = format("[%s] Start to upload pluggable artifact using plugin `%s`.", PRODUCT_NAME, pluginId);
        goPublisher.taggedConsumeLine(GoPublisher.PUBLISH, message);
        LOGGER.info(message);
        final PublishArtifactResponse publishArtifactResponse = artifactExtension.publishArtifact(pluginId, artifactPlan, artifactStore, workingDirectory.getAbsolutePath(), environmentVariableContext);
        if (!publishArtifactResponse.getMetadata().isEmpty()) {
            final String artifactId = (String) artifactPlan.getPluggableArtifactConfiguration().get("id");
            pluggableArtifactMetadata.addMetadata(pluginId, artifactId, publishArtifactResponse.getMetadata());
        }
    } catch (RuntimeException e) {
        failedArtifact.add(artifactPlan);
        goPublisher.taggedConsumeLine(GoPublisher.ERR, format("[%s] %s", PRODUCT_NAME, e.getMessage()));
        LOGGER.error(e.getMessage(), e);
    }
}
Also used : PublishArtifactResponse(com.thoughtworks.go.plugin.access.artifact.model.PublishArtifactResponse)

Example 9 with PublishArtifactResponse

use of com.thoughtworks.go.plugin.access.artifact.model.PublishArtifactResponse in project gocd by gocd.

the class ArtifactsPublisherTest method shouldRegisterAndDeRegisterArtifactRequestProcessBeforeAndAfterPublishingPluggableArtifact.

@Test
public void shouldRegisterAndDeRegisterArtifactRequestProcessBeforeAndAfterPublishingPluggableArtifact() {
    final ArtifactStore s3ArtifactStore = new ArtifactStore("s3", "cd.go.s3", create("access_key", false, "some-key"));
    final ArtifactStores artifactStores = new ArtifactStores(s3ArtifactStore);
    final ArtifactPlan s3ArtifactPlan = new ArtifactPlan(new PluggableArtifactConfig("installers", "s3", create("Baz", true, "Car")));
    when(artifactExtension.publishArtifact(eq("cd.go.s3"), eq(s3ArtifactPlan), eq(s3ArtifactStore), anyString(), eq(env))).thenReturn(new PublishArtifactResponse(Collections.singletonMap("src", "s3://dist")));
    new ArtifactsPublisher(publisher, artifactExtension, artifactStores, registry, workingFolder).publishArtifacts(Arrays.asList(s3ArtifactPlan), env);
    InOrder inOrder = inOrder(registry, artifactExtension);
    inOrder.verify(registry, times(1)).registerProcessorFor(eq(CONSOLE_LOG.requestName()), any(ArtifactRequestProcessor.class));
    inOrder.verify(artifactExtension, times(1)).publishArtifact("cd.go.s3", s3ArtifactPlan, s3ArtifactStore, workingFolder.getAbsolutePath(), env);
    inOrder.verify(registry, times(1)).removeProcessorFor(CONSOLE_LOG.requestName());
}
Also used : PluggableArtifactConfig(com.thoughtworks.go.config.PluggableArtifactConfig) ArtifactStores(com.thoughtworks.go.config.ArtifactStores) InOrder(org.mockito.InOrder) ArtifactStore(com.thoughtworks.go.config.ArtifactStore) PublishArtifactResponse(com.thoughtworks.go.plugin.access.artifact.model.PublishArtifactResponse) Test(org.junit.jupiter.api.Test)

Example 10 with PublishArtifactResponse

use of com.thoughtworks.go.plugin.access.artifact.model.PublishArtifactResponse in project gocd by gocd.

the class ArtifactsPublisherTest method shouldErrorOutWhenFailedToCreateFolderToWritePluggableArtifactMetadata.

@Test
public void shouldErrorOutWhenFailedToCreateFolderToWritePluggableArtifactMetadata() {
    Assumptions.assumeFalse(IS_WINDOWS, "Do not run on windows.");
    final ArtifactStore artifactStore = new ArtifactStore("s3", "cd.go.s3", create("Foo", false, "Bar"));
    final ArtifactStores artifactStores = new ArtifactStores(artifactStore);
    final ArtifactPlan artifactPlan = new ArtifactPlan(new PluggableArtifactConfig("installers", "s3", create("Baz", true, "Car")));
    when(artifactExtension.publishArtifact(eq("cd.go.s3"), eq(artifactPlan), eq(artifactStore), anyString(), eq(env))).thenReturn(new PublishArtifactResponse(Collections.singletonMap("Foo", "Bar")));
    workingFolder.setWritable(false);
    assertThatThrownBy(() -> new ArtifactsPublisher(publisher, artifactExtension, artifactStores, registry, workingFolder).publishArtifacts(Arrays.asList(artifactPlan), env)).isInstanceOf(RuntimeException.class).hasMessageContaining("[go] Could not create pluggable artifact metadata folder");
}
Also used : PluggableArtifactConfig(com.thoughtworks.go.config.PluggableArtifactConfig) ArtifactStores(com.thoughtworks.go.config.ArtifactStores) ArtifactStore(com.thoughtworks.go.config.ArtifactStore) PublishArtifactResponse(com.thoughtworks.go.plugin.access.artifact.model.PublishArtifactResponse) Test(org.junit.jupiter.api.Test)

Aggregations

PublishArtifactResponse (com.thoughtworks.go.plugin.access.artifact.model.PublishArtifactResponse)11 ArtifactStore (com.thoughtworks.go.config.ArtifactStore)8 Test (org.junit.jupiter.api.Test)8 ArtifactStores (com.thoughtworks.go.config.ArtifactStores)6 PluggableArtifactConfig (com.thoughtworks.go.config.PluggableArtifactConfig)6 ArtifactPlan (com.thoughtworks.go.domain.ArtifactPlan)2 GoPluginApiRequest (com.thoughtworks.go.plugin.api.request.GoPluginApiRequest)2 GoPublisher (com.thoughtworks.go.work.GoPublisher)2 InOrder (org.mockito.InOrder)2 EnvironmentVariableContext (com.thoughtworks.go.util.command.EnvironmentVariableContext)1 IOException (java.io.IOException)1 Test (org.junit.Test)1