@Override protected RetryStrategy getRetryStrategy() { // always retry return super.getRetryStrategy(); } }
@Override public void execute(Arguments arguments) { Profile profile = new Profile(arguments.name, arguments.getLabel(), arguments.getDescription(), EntityScope.SYSTEM, arguments.getProvisioner()); profileService.createIfNotExists(arguments.getId(), profile); }
@Override public void validate() { if (namespace == null || namespace.isEmpty()) { throw new IllegalArgumentException("Namespace must be specified"); } if (application == null || application.isEmpty()) { throw new IllegalArgumentException("Application must be specified"); } if (type == null || type.isEmpty()) { throw new IllegalArgumentException("Program type must be specified"); } if (name == null || name.isEmpty()) { throw new IllegalArgumentException("Program name must be specified"); } getId(); } }
@Test public void testMissingProvisionerInfo() throws Exception { SystemProfileCreator.Arguments arguments = new SystemProfileCreator.Arguments("name", "label", "desc", null); BootstrapStepResult result = profileCreator.execute("label", GSON.toJsonTree(arguments).getAsJsonObject()); Assert.assertEquals(BootstrapStepResult.Status.FAILED, result.getStatus()); }
@Test public void testAllPreferenceSet() throws Exception { Map<String, String> preferences = new HashMap<>(); preferences.put("p1", "v1"); preferences.put("p2", "v2"); SystemPreferenceSetter.Arguments arguments = new SystemPreferenceSetter.Arguments(preferences); BootstrapStepResult result = systemPreferenceSetter.execute("label", GSON.toJsonTree(arguments).getAsJsonObject()); Assert.assertEquals(BootstrapStepResult.Status.SUCCEEDED, result.getStatus()); Assert.assertEquals(preferences, preferencesService.getProperties()); }
@Test(expected = IllegalArgumentException.class) public void invalidProgramTypeThrowsException() { ProgramStarter.Arguments arguments = new ProgramStarter.Arguments("ns", "app", "PORKFLOW", "name"); arguments.validate(); }
@Override public void execute(Arguments arguments) throws BadRequestException, NotFoundException, ProfileConflictException { try { preferencesService.addProperties(arguments.getPreferences()); } catch (RuntimeException e) { // runtime exceptions are those propagated by some lower layer, usually due to some transaction failure // these should be safe to retry, at least up to the default time limit // as always, it is almost impossible to do this accurately without refactoring a bunch of layers below throw new RetryableException(e); } }
@Override public void validate() { super.validate(); if (name == null || name.isEmpty()) { throw new IllegalArgumentException("Profile name must be specified"); } getId(); } }
@Override public void validate() { super.validate(); if (namespace == null || namespace.isEmpty()) { throw new IllegalArgumentException("Namespace must be specified"); } if (name == null || name.isEmpty()) { throw new IllegalArgumentException("Application name must be specified"); } getId(); } }
@Test public void invalidStructureFails() throws Exception { JsonObject argumentsObj = new JsonObject(); argumentsObj.addProperty("namespace", "ns"); argumentsObj.addProperty("application", "app"); argumentsObj.addProperty("type", "WORKFLOW"); argumentsObj.add("name", new JsonObject()); BootstrapStepResult result = programStarter.execute("label", argumentsObj); Assert.assertEquals(BootstrapStepResult.Status.FAILED, result.getStatus()); } }
@Test public void testInvalidArgumentStructure() throws Exception { JsonObject arguments = new JsonObject(); arguments.addProperty("name", "p1"); arguments.addProperty("description", "desc"); arguments.addProperty("label", "some label"); // this is invalid, should be an object arguments.addProperty("provisioner", "native"); BootstrapStepResult result = profileCreator.execute("label", arguments); Assert.assertEquals(BootstrapStepResult.Status.FAILED, result.getStatus()); }
@Test public void invalidStructureFails() throws Exception { JsonObject argumentsObj = new JsonObject(); argumentsObj.addProperty("namespace", "ns"); argumentsObj.addProperty("name", "app"); argumentsObj.addProperty("artifact", "name-1.0.0"); BootstrapStepResult result = appCreator.execute("label", argumentsObj); Assert.assertEquals(BootstrapStepResult.Status.FAILED, result.getStatus()); } }
@Test public void testAlreadyExistsDoesNotError() throws Exception { profileService.saveProfile(ProfileId.NATIVE, Profile.NATIVE); BootstrapStepResult result = nativeProfileCreator.execute("label", new JsonObject()); BootstrapStepResult expected = new BootstrapStepResult("label", BootstrapStepResult.Status.SUCCEEDED); Assert.assertEquals(expected, result); Assert.assertEquals(Profile.NATIVE, profileService.getProfile(ProfileId.NATIVE)); } }
@Override public void execute(Arguments arguments) { Profile profile = new Profile(arguments.name, arguments.getLabel(), arguments.getDescription(), EntityScope.SYSTEM, arguments.getProvisioner()); profileService.createIfNotExists(arguments.getId(), profile); }
@Test public void testMissingProfileName() throws Exception { List<ProvisionerPropertyValue> properties = new ArrayList<>(); properties.add(new ProvisionerPropertyValue("name1", "val1", true)); properties.add(new ProvisionerPropertyValue("name2", "val2", true)); ProvisionerInfo provisionerInfo = new ProvisionerInfo(MockProvisioner.NAME, properties); SystemProfileCreator.Arguments arguments = new SystemProfileCreator.Arguments("", "label", "desc", provisionerInfo); BootstrapStepResult result = profileCreator.execute("label", GSON.toJsonTree(arguments).getAsJsonObject()); Assert.assertEquals(BootstrapStepResult.Status.FAILED, result.getStatus()); }
@Test public void testExistingIsUnmodified() throws Exception { Map<String, String> preferences = new HashMap<>(); preferences.put("p1", "v1"); preferencesService.setProperties(preferences); preferences.put("p2", "v2"); preferences.put("p1", "v3"); SystemPreferenceSetter.Arguments arguments = new SystemPreferenceSetter.Arguments(preferences); BootstrapStepResult result = systemPreferenceSetter.execute("label", GSON.toJsonTree(arguments).getAsJsonObject()); Assert.assertEquals(BootstrapStepResult.Status.SUCCEEDED, result.getStatus()); Map<String, String> expected = new HashMap<>(); // p1 should not have been overridden expected.put("p1", "v1"); expected.put("p2", "v2"); Assert.assertEquals(expected, preferencesService.getProperties()); } }
@Override public void execute(Arguments arguments) throws BadRequestException, NotFoundException, ProfileConflictException { try { preferencesService.addProperties(arguments.getPreferences()); } catch (RuntimeException e) { // runtime exceptions are those propagated by some lower layer, usually due to some transaction failure // these should be safe to retry, at least up to the default time limit // as always, it is almost impossible to do this accurately without refactoring a bunch of layers below throw new RetryableException(e); } }
@Override public void validate() { super.validate(); if (name == null || name.isEmpty()) { throw new IllegalArgumentException("Profile name must be specified"); } getId(); } }
@Override public void validate() { super.validate(); if (namespace == null || namespace.isEmpty()) { throw new IllegalArgumentException("Namespace must be specified"); } if (name == null || name.isEmpty()) { throw new IllegalArgumentException("Application name must be specified"); } getId(); } }
@Override public void validate() { if (namespace == null || namespace.isEmpty()) { throw new IllegalArgumentException("Namespace must be specified"); } if (application == null || application.isEmpty()) { throw new IllegalArgumentException("Application must be specified"); } if (type == null || type.isEmpty()) { throw new IllegalArgumentException("Program type must be specified"); } if (name == null || name.isEmpty()) { throw new IllegalArgumentException("Program name must be specified"); } getId(); } }