Search in sources :

Example 1 with PublishArtifactResponse

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

the class ArtifactExtensionTest method shouldSubmitPublishArtifactRequest.

@Test
public void shouldSubmitPublishArtifactRequest() throws JSONException {
    final String responseBody = "{\n" + "  \"metadata\": {\n" + "    \"artifact-version\": \"10.12.0\"\n" + "  }\n" + "}";
    when(pluginManager.submitTo(eq(PLUGIN_ID), eq(ARTIFACT_EXTENSION), requestArgumentCaptor.capture())).thenReturn(DefaultGoPluginApiResponse.success(responseBody));
    final PublishArtifactResponse response = artifactExtension.publishArtifact(PLUGIN_ID, new ArtifactPlan("{\"id\":\"installer\",\"storeId\":\"docker\"}"), new ArtifactStore("docker", "cd.go.docker"), "/temp");
    final GoPluginApiRequest request = requestArgumentCaptor.getValue();
    assertThat(request.extension(), is(ARTIFACT_EXTENSION));
    assertThat(request.requestName(), is(REQUEST_PUBLISH_ARTIFACT));
    final String expectedJSON = "{\n" + "  \"artifact_plan\": {\n" + "    \"id\": \"installer\",\n" + "    \"storeId\": \"docker\"\n" + "  },\n" + "  \"artifact_store\": {\n" + "    \"configuration\": {},\n" + "    \"id\": \"docker\"\n" + "  },\n" + "  \"agent_working_directory\": \"/temp\"\n" + "}";
    JSONAssert.assertEquals(expectedJSON, request.requestBody(), true);
    assertThat(response.getMetadata().size(), is(1));
    assertThat(response.getMetadata(), hasEntry("artifact-version", "10.12.0"));
}
Also used : GoPluginApiRequest(com.thoughtworks.go.plugin.api.request.GoPluginApiRequest) ArtifactPlan(com.thoughtworks.go.domain.ArtifactPlan) ArtifactStore(com.thoughtworks.go.config.ArtifactStore) PublishArtifactResponse(com.thoughtworks.go.plugin.access.artifact.model.PublishArtifactResponse) Test(org.junit.Test)

Example 2 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) {
    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());
        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 3 with PublishArtifactResponse

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

the class ArtifactExtensionTestBase method shouldSubmitPublishArtifactRequest.

@Test
public void shouldSubmitPublishArtifactRequest() {
    final String responseBody = "{\n" + "  \"metadata\": {\n" + "    \"artifact-version\": \"10.12.0\"\n" + "  }\n" + "}";
    when(pluginManager.submitTo(eq(PLUGIN_ID), eq(ARTIFACT_EXTENSION), requestArgumentCaptor.capture())).thenReturn(DefaultGoPluginApiResponse.success(responseBody));
    ArtifactPlan artifactPlan = new ArtifactPlan("{\"id\":\"installer\",\"storeId\":\"docker\"}");
    ArtifactStore artifactStore = new ArtifactStore("docker", "cd.go.docker");
    EnvironmentVariableContext env = new EnvironmentVariableContext("foo", "bar");
    final PublishArtifactResponse response = artifactExtension.publishArtifact(PLUGIN_ID, artifactPlan, artifactStore, "/temp", env);
    final GoPluginApiRequest request = requestArgumentCaptor.getValue();
    assertThat(request.extension(), is(ARTIFACT_EXTENSION));
    assertThat(request.requestName(), is(REQUEST_PUBLISH_ARTIFACT));
    final String expectedJSON = "{" + "  \"artifact_plan\": {" + "    \"id\": \"installer\"," + "    \"storeId\": \"docker\"" + "  }," + "  \"artifact_store\": {" + "    \"configuration\": {}," + "    \"id\": \"docker\"" + "  }," + "  \"environment_variables\": {" + "    \"foo\": \"bar\"" + "  }," + "  \"agent_working_directory\": \"/temp\"" + "}";
    assertThatJson(expectedJSON).isEqualTo(request.requestBody());
    assertThat(response.getMetadata().size(), is(1));
    assertThat(response.getMetadata(), hasEntry("artifact-version", "10.12.0"));
}
Also used : GoPluginApiRequest(com.thoughtworks.go.plugin.api.request.GoPluginApiRequest) ArtifactPlan(com.thoughtworks.go.domain.ArtifactPlan) ArtifactStore(com.thoughtworks.go.config.ArtifactStore) PublishArtifactResponse(com.thoughtworks.go.plugin.access.artifact.model.PublishArtifactResponse) EnvironmentVariableContext(com.thoughtworks.go.util.command.EnvironmentVariableContext) Test(org.junit.jupiter.api.Test)

Example 4 with PublishArtifactResponse

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

the class ArtifactMessageConverterV1Test method publishArtifactResponse_shouldDeserializeFromJson.

@Test
public void publishArtifactResponse_shouldDeserializeFromJson() {
    final ArtifactMessageConverterV1 converter = new ArtifactMessageConverterV1();
    final PublishArtifactResponse response = converter.publishArtifactResponse("{\n" + "  \"metadata\": {\n" + "    \"artifact-version\": \"10.12.0\"\n" + "  }\n" + "}");
    MatcherAssert.assertThat(response.getMetadata().size(), is(1));
    MatcherAssert.assertThat(response.getMetadata(), hasEntry("artifact-version", "10.12.0"));
}
Also used : PublishArtifactResponse(com.thoughtworks.go.plugin.access.artifact.model.PublishArtifactResponse) Test(org.junit.jupiter.api.Test)

Example 5 with PublishArtifactResponse

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

the class ArtifactsPublisherTest method shouldContinueWithOtherPluginWhenPublishArtifactCallFailsForOnePlugin.

@Test
public void shouldContinueWithOtherPluginWhenPublishArtifactCallFailsForOnePlugin() throws IOException {
    final ArtifactStore s3ArtifactStore = new ArtifactStore("s3", "cd.go.s3", create("access_key", false, "some-key"));
    final ArtifactStore dockerArtifactStore = new ArtifactStore("docker", "cd.go.docker", create("registry-url", false, "docker.io"));
    final ArtifactStores artifactStores = new ArtifactStores(s3ArtifactStore, dockerArtifactStore);
    final ArtifactPlan s3ArtifactPlan = new ArtifactPlan(new PluggableArtifactConfig("installers", "s3", create("Baz", true, "Car")));
    final ArtifactPlan dockerArtifactPlan = new ArtifactPlan(new PluggableArtifactConfig("test-reports", "docker", create("junit", false, "junit.xml")));
    when(artifactExtension.publishArtifact(eq("cd.go.s3"), eq(s3ArtifactPlan), eq(s3ArtifactStore), anyString(), eq(env))).thenThrow(new RuntimeException("Interaction with plugin `cd.go.s3` failed."));
    when(artifactExtension.publishArtifact(eq("cd.go.docker"), eq(dockerArtifactPlan), eq(dockerArtifactStore), anyString(), eq(env))).thenReturn(new PublishArtifactResponse(Collections.singletonMap("tag", "10.12.0")));
    try {
        new ArtifactsPublisher(publisher, artifactExtension, artifactStores, registry, workingFolder).publishArtifacts(Arrays.asList(s3ArtifactPlan, dockerArtifactPlan), env);
        fail("Should throw error for pluggable artifact [installers].");
    } catch (Exception e) {
        assertThat(uploadedPluggableMetadataFiles(publisher.publishedFiles()), containsInAnyOrder("cd.go.docker.json"));
        assertThat(publisher.getMessage(), containsString("[go] Interaction with plugin `cd.go.s3` failed"));
        assertThat(e.getMessage(), containsString("[go] Uploading finished. Failed to upload [installers]."));
    }
}
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) IOException(java.io.IOException) 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