/** * Returns the context of this goal execution. If the context has not been set before, it is constructed * by reading tenant, space and app information from the configuration obtained from {@link AbstractGoal#getConfiguration()}. * @return */ public synchronized final GoalContext getGoalContext() { if(this.goalContext==null) { final Configuration c = this.getConfiguration().getConfiguration(); this.goalContext = new GoalContext(); // Tenant if(!this.getConfiguration().isEmpty(CoreConfiguration.TENANT_TOKEN)) this.goalContext.setTenant(new Tenant(c.getString(CoreConfiguration.TENANT_TOKEN))); // Space if(!this.getConfiguration().isEmpty(CoreConfiguration.SPACE_TOKEN)) { final Space space = new Space(); space.setSpaceToken(c.getString(CoreConfiguration.SPACE_TOKEN)); this.goalContext.setSpace(space); } // App if(Application.canBuildApplication(c.getString(CoreConfiguration.APP_CTX_GROUP), c.getString(CoreConfiguration.APP_CTX_ARTIF), c.getString(CoreConfiguration.APP_CTX_VERSI))) { final Application a = new Application(c.getString(CoreConfiguration.APP_CTX_GROUP), c.getString(CoreConfiguration.APP_CTX_ARTIF), c.getString(CoreConfiguration.APP_CTX_VERSI)); if(a.isComplete()) this.goalContext.setApplication(a); else log.warn("Incomplete application context: " + a.toString()); } } return this.goalContext; }
final Space space = new Space(); space.setSpaceToken(c.getString(CoreConfiguration.SPACE_TOKEN)); ctx.setSpace(space);
@Override protected void executeTasks() throws Exception { final Space s = new Space(); this.updateFromConfig(s); // Warn that any provided space token is ignored when creating a new space if(s.isValidSpaceToken()) log.warn("Upon space creation a new token will be generated, the current token [" + s.getSpaceToken() + "] will be ignored"); // Check that name and description are provided if(!s.hasNameAndDescription()) { this.skipGoalUpload(); throw new GoalExecutionException("Space creation requires name and description, adjust the configuration accordingly", null); } // Create space and print token to be used in configuration this.createdSpace = BackendConnector.getInstance().createSpace(this.getGoalContext(), s); if(this.createdSpace==null) { log.error("Space creation failed"); } else { log.info("Space creation succeeded: Use space token [" + this.createdSpace.spaceToken + "] for configuration setting [" + CoreConfiguration.SPACE_TOKEN + "]"); // Update context so that goal execution is uploaded properly this.getGoalContext().setSpace(this.createdSpace); } }