use of com.thoughtworks.go.plugin.access.configrepo.contract.CRParseResult in project gocd by gocd.
the class JsonMessageHandler1_0Test method shouldNotErrorWhenTargetVersionInResponse.
@Test
public void shouldNotErrorWhenTargetVersionInResponse() {
String json = "{\n" + " \"target_version\" : 1,\n" + " \"pipelines\" : [],\n" + " \"errors\" : []\n" + "}";
makeMigratorReturnSameJSON();
CRParseResult result = handler.responseMessageForParseDirectory(json);
assertFalse(result.hasErrors());
}
use of com.thoughtworks.go.plugin.access.configrepo.contract.CRParseResult in project gocd by gocd.
the class ConfigRepoPlugin method load.
@Override
public PartialConfig load(File configRepoCheckoutDirectory, PartialConfigLoadContext context) {
Collection<CRConfigurationProperty> cRconfigurations = getCrConfigurations(context.configuration());
CRParseResult crPartialConfig = parseDirectory(configRepoCheckoutDirectory, cRconfigurations);
return configConverter.toPartialConfig(crPartialConfig, context);
}
use of com.thoughtworks.go.plugin.access.configrepo.contract.CRParseResult in project gocd by gocd.
the class JsonMessageHandler1_0 method responseMessageForParseDirectory.
@Override
public CRParseResult responseMessageForParseDirectory(String responseBody) {
ErrorCollection errors = new ErrorCollection();
try {
ResponseScratch responseMap = parseResponseForMigration(responseBody);
ParseDirectoryResponseMessage parseDirectoryResponseMessage;
if (responseMap.target_version == null) {
errors.addError("Plugin response message", "missing 'target_version' field");
return new CRParseResult(errors);
} else {
int version = responseMap.target_version;
while (version < CURRENT_CONTRACT_VERSION) {
version++;
responseBody = migrate(responseBody, version);
}
// after migration, json should match contract
parseDirectoryResponseMessage = codec.getGson().fromJson(responseBody, ParseDirectoryResponseMessage.class);
parseDirectoryResponseMessage.validateResponse(errors);
errors.addErrors(parseDirectoryResponseMessage.getPluginErrors());
return new CRParseResult(parseDirectoryResponseMessage.getEnvironments(), parseDirectoryResponseMessage.getPipelines(), errors);
}
} catch (Exception ex) {
StringBuilder builder = new StringBuilder();
builder.append("Unexpected error when handling plugin response").append('\n');
builder.append(ex);
// "location" of error is runtime. This is what user will see in config repo errors list.
errors.addError("runtime", builder.toString());
LOGGER.error(builder.toString(), ex);
return new CRParseResult(errors);
}
}
Aggregations