-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added changes on current material types to support Stage material * Added Stage material params * Removed StagePipeline param * Added new rendering logic to template * Create StageFetchExecutor (still missing stage counter find feature) * Reverted changes on other fetch executor names * Added logic to find latest stage counter * Adjustments to UI
- Loading branch information
Showing
10 changed files
with
346 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
fetch/src/main/java/com/indix/gocd/s3fetch/SelfFetchExecutor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package com.indix.gocd.s3fetch; | ||
|
||
import com.indix.gocd.utils.Constants; | ||
import com.indix.gocd.utils.GoEnvironment; | ||
import com.indix.gocd.utils.store.S3ArtifactStore; | ||
import org.apache.commons.lang3.StringUtils; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class SelfFetchExecutor extends FetchExecutor { | ||
|
||
@Override | ||
protected String getArtifactsLocationTemplate(Config config, GoEnvironment env) { | ||
|
||
String prefix = config.getSourcePrefix(); | ||
String source = config.getSource(); | ||
|
||
if (StringUtils.isBlank(prefix)) { | ||
String pipeline = env.get("GO_PIPELINE_NAME"); | ||
String pipelineCounter = env.get("GO_PIPELINE_COUNTER"); | ||
String stage = config.getStage(); | ||
String job = config.getJob(); | ||
String bucket = getBucket(config, env); | ||
|
||
final S3ArtifactStore store = getS3ArtifactStore(env, bucket); | ||
prefix = store.getLatestPrefix(pipeline, stage, job, pipelineCounter); | ||
|
||
if (StringUtils.isBlank(prefix)) { | ||
throw new RuntimeException( | ||
String.format("Could not determine stage counter on s3 with path: s3://%s/%s/%s/%s/%s.", | ||
bucket, | ||
pipeline, | ||
stage, | ||
job, | ||
pipelineCounter)); | ||
} | ||
} | ||
|
||
return prefix + "/" + source; | ||
} | ||
|
||
@Override | ||
public Map<String, String> validate(Config config) { | ||
Map<String, String> errors = new HashMap<>(); | ||
|
||
if (StringUtils.isBlank(config.getSourcePrefix())) { | ||
|
||
if (StringUtils.isBlank(config.getStage())) { | ||
errors.put(Constants.STAGE, Constants.REQUIRED_FIELD_MESSAGE); | ||
} | ||
if (StringUtils.isBlank(config.getJob())) { | ||
errors.put(Constants.JOB, Constants.REQUIRED_FIELD_MESSAGE); | ||
} | ||
} | ||
|
||
if (StringUtils.isBlank(config.getSource())) { | ||
errors.put(Constants.SOURCE, Constants.REQUIRED_FIELD_MESSAGE); | ||
} | ||
|
||
return errors; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
fetch/src/test/java/com/indix/gocd/s3fetch/SelfFetchExecutorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package com.indix.gocd.s3fetch; | ||
|
||
import com.indix.gocd.utils.Constants; | ||
import com.indix.gocd.utils.Context; | ||
import com.indix.gocd.utils.TaskExecutionResult; | ||
import com.indix.gocd.utils.mocks.MockContext; | ||
import com.indix.gocd.utils.store.S3ArtifactStore; | ||
import com.indix.gocd.utils.utils.Maps; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import java.util.Map; | ||
|
||
import static com.indix.gocd.utils.Constants.*; | ||
import static org.hamcrest.core.Is.is; | ||
import static org.junit.Assert.*; | ||
import static org.mockito.Matchers.any; | ||
import static org.mockito.Mockito.*; | ||
|
||
public class SelfFetchExecutorTest { | ||
|
||
private Maps.MapBuilder<String, String> mockEnvironmentVariables; | ||
private FetchExecutor fetchExecutor; | ||
private Config config; | ||
private S3ArtifactStore store; | ||
|
||
private final String PIPELINE = "pipeline"; | ||
private final String PIPELINE_COUNTER = "1"; | ||
private final String STAGE = "stage"; | ||
private final String JOB = "job"; | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
mockEnvironmentVariables = Maps.<String, String>builder() | ||
.with(AWS_SECRET_ACCESS_KEY, "secretKey") | ||
.with(AWS_ACCESS_KEY_ID, "accessId") | ||
.with(GO_ARTIFACTS_S3_BUCKET, "bucket") | ||
.with(GO_SERVER_DASHBOARD_URL, "http://go.server:8153") | ||
.with("GO_PIPELINE_NAME", PIPELINE) | ||
.with("GO_PIPELINE_COUNTER", PIPELINE_COUNTER); | ||
|
||
config = new Config(Maps.builder() | ||
.with(Constants.STAGE, Maps.builder().with("value", STAGE).build()) | ||
.with(Constants.JOB, Maps.builder().with("value", JOB).build()) | ||
.with(Constants.SOURCE, Maps.builder().with("value", "source").build()) | ||
.with(Constants.DESTINATION, Maps.builder().with("value", "artifacts").build()) | ||
.build()); | ||
|
||
store = mock(S3ArtifactStore.class); | ||
fetchExecutor = spy(new SelfFetchExecutor()); | ||
doReturn(store).when(fetchExecutor).getS3ArtifactStore(any(), any()); | ||
} | ||
|
||
@Test | ||
public void shouldBeFailureIfCouldntFindS3Path() { | ||
Map<String, String> mockVariables = mockEnvironmentVariables.build(); | ||
doReturn(null).when(store).getLatestPrefix(PIPELINE, STAGE, JOB, PIPELINE_COUNTER); | ||
TaskExecutionResult result = fetchExecutor.execute(config, mockContext(mockVariables) ); | ||
|
||
assertFalse(result.isSuccessful()); | ||
assertEquals("Failure while downloading artifacts - Could not determine stage counter on s3 with path: s3://bucket/pipeline/stage/job/1.", result.message()); | ||
} | ||
|
||
@Test | ||
public void shouldBeSuccessWhenAbleToFindSS3Path() { | ||
Map<String, String> mockVariables = mockEnvironmentVariables.build(); | ||
doReturn("sourcePrefix").when(store).getLatestPrefix(PIPELINE, STAGE, JOB, PIPELINE_COUNTER); | ||
TaskExecutionResult result = fetchExecutor.execute(config, mockContext(mockVariables) ); | ||
|
||
assertTrue(result.isSuccessful()); | ||
assertThat(result.message(), is("Fetched all artifacts")); | ||
verify(store).getPrefix("sourcePrefix/source", "here/artifacts"); | ||
} | ||
|
||
@Test | ||
public void shouldBeSuccessWhenCustomPrefixProvided() { | ||
Map<String, String> mockVariables = mockEnvironmentVariables.build(); | ||
config = new Config(Maps.builder() | ||
.with(Constants.SOURCE, Maps.builder().with("value", "source").build()) | ||
.with(Constants.SOURCE_PREFIX, Maps.builder().with("value", "sourcePrefix").build()) | ||
.with(Constants.DESTINATION, Maps.builder().with("value", "artifacts").build()) | ||
.build()); | ||
TaskExecutionResult result = fetchExecutor.execute(config, mockContext(mockVariables) ); | ||
|
||
assertTrue(result.isSuccessful()); | ||
assertThat(result.message(), is("Fetched all artifacts")); | ||
verify(store).getPrefix("sourcePrefix/source", "here/artifacts"); | ||
} | ||
|
||
private Context mockContext(final Map<String, String> environmentMap) { | ||
Map<String, Object> contextMap = Maps.<String, Object>builder() | ||
.with("environmentVariables", environmentMap) | ||
.with("workingDirectory", "here") | ||
.build(); | ||
return new MockContext(contextMap); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.