public Map<AgentInstance, Collection<String>> agentEnvironmentMap() { Map<AgentInstance, Collection<String>> allAgents = new LinkedHashMap<>(); for (AgentInstance agentInstance : agentInstances.allAgents()) { allAgents.put(agentInstance, environmentConfigService.environmentsFor(agentInstance.getUuid())); } return allAgents; }
public List<EnvironmentViewModel> listAllMergedEnvironments() { ArrayList<EnvironmentViewModel> environmentViewModels = new ArrayList<>(); List<EnvironmentConfig> allMergedEnvironments = getAllMergedEnvironments(); for (EnvironmentConfig environmentConfig : allMergedEnvironments) { environmentViewModels.add(new EnvironmentViewModel(environmentConfig)); } return environmentViewModels; }
public List<EnvironmentConfig> getAllMergedEnvironments() { return environmentNames().stream().map(environmentName -> EnvironmentConfigService.this.getMergedEnvironmentforDisplay(environmentName.toString(), new HttpLocalizedOperationResult()).getConfigElement()).collect(Collectors.toList()); }
public List<EnvironmentConfig> getAllLocalEnvironments() { return environmentNames().stream().map(environmentName -> EnvironmentConfigService.this.getEnvironmentForEdit(environmentName.toString())).collect(Collectors.toList()); }
@Override public EnvironmentConfig doFetchEntityFromConfig(String name) { ConfigElementForEdit<EnvironmentConfig> mergedEnvironmentforDisplay = environmentConfigService.getMergedEnvironmentforDisplay(name, new HttpLocalizedOperationResult()); return mergedEnvironmentforDisplay == null ? null : mergedEnvironmentforDisplay.getConfigElement(); }
JobPlan findMatchingJob(AgentInstance agent) { List<JobPlan> filteredJobPlans = environmentConfigService.filterJobsByAgent(jobPlans, agent.getUuid()); JobPlan match = null; if (!agent.isElastic()) { match = agent.firstMatching(filteredJobPlans); } else { for (JobPlan jobPlan : filteredJobPlans) { if (jobPlan.requiresElasticAgent() && elasticAgentPluginService.shouldAssignWork(agent.elasticAgentMetadata(), environmentConfigService.envForPipeline(jobPlan.getPipelineName()), jobPlan.getElasticProfile(), jobPlan.getIdentifier())) { match = jobPlan; break; } } } if (match != null) { jobPlans.remove(match); } return match; }
public List<WaitingJobPlan> waitingJobPlans() { List<JobPlan> jobPlans = orderedScheduledBuilds(); List<WaitingJobPlan> waitingJobPlans = new ArrayList<>(); for (JobPlan jobPlan : jobPlans) { String envForJob = environmentConfigService.envForPipeline(jobPlan.getPipelineName()); waitingJobPlans.add(new WaitingJobPlan(jobPlan, envForJob)); } return waitingJobPlans; }
public String remove(Request request, Response response) { String environmentName = request.params("name"); HttpLocalizedOperationResult result = new HttpLocalizedOperationResult(); EnvironmentConfig environmentConfig = fetchEntityFromConfig(environmentName); environmentConfigService.deleteEnvironment(environmentConfig, currentUsername(), result); return handleSimpleMessageResponse(response, result); }
public String create(Request request, Response response) { final BasicEnvironmentConfig environmentConfigToCreate = (BasicEnvironmentConfig) buildEntityFromRequestBody(request); final HttpLocalizedOperationResult operationResult = new HttpLocalizedOperationResult(); haltIfEntityWithSameNameExists(environmentConfigToCreate); environmentConfigService.createEnvironment(environmentConfigToCreate, currentUsername(), operationResult); setEtagHeader(environmentConfigToCreate, response); return handleCreateOrUpdateResponse(request, response, environmentConfigToCreate, operationResult); }
private SchedulingContext schedulingContext(String username, PipelineConfig pipelineConfig, StageConfig stageConfig) { Agents availableAgents = environmentConfigService.agentsForPipeline(pipelineConfig.name()); SchedulingContext context = new DefaultSchedulingContext(username, availableAgents, elasticProfileService.listAll()); context = context.overrideEnvironmentVariables(pipelineConfig.getVariables()); context = context.overrideEnvironmentVariables(stageConfig.getVariables()); return context; }
private Work createWork(final AgentInstance agent, final JobPlan job) { try { return (Work) transactionTemplate.transactionSurrounding(() -> { final String agentUuid = agent.getUuid(); //TODO: Use fullPipeline and get the Stage from it? final Pipeline pipeline; try { pipeline = scheduledPipelineLoader.pipelineWithPasswordAwareBuildCauseByBuildId(job.getJobId()); } catch (StaleMaterialsOnBuildCause e) { return NO_WORK; } List<Task> tasks = goConfigService.tasksForJob(pipeline.getName(), job.getIdentifier().getStageName(), job.getName()); final List<Builder> builders = builderFactory.buildersForTasks(pipeline, tasks, resolver); return transactionTemplate.execute((TransactionCallback) status -> { if (scheduleService.updateAssignedInfo(agentUuid, job)) { return NO_WORK; } EnvironmentVariableContext contextFromEnvironment = environmentConfigService.environmentVariableContextFor(job.getIdentifier().getPipelineName()); final ArtifactStores requiredArtifactStores = goConfigService.artifactStores().getArtifactStores(getArtifactStoreIdsRequiredByArtifactPlans(job.getArtifactPlans())); BuildAssignment buildAssignment = BuildAssignment.create(job, pipeline.getBuildCause(), builders, pipeline.defaultWorkingFolder(), contextFromEnvironment, requiredArtifactStores); return new BuildWork(buildAssignment, systemEnvironment.consoleLogCharset()); }); }); } catch (PipelineNotFoundException e) { removeJobIfNotPresentInCruiseConfig(goConfigService.getCurrentConfig(), job); throw e; } }
private void haltIfEntityWithSameNameExists(EnvironmentConfig environmentConfig) { HttpLocalizedOperationResult result = new HttpLocalizedOperationResult(); ConfigElementForEdit<EnvironmentConfig> existingEnvironmentConfig = environmentConfigService.getMergedEnvironmentforDisplay(environmentConfig.name().toString(), result); if (existingEnvironmentConfig == null) { return; } environmentConfig.addError("name", format("Environment name should be unique. Environment with name '%s' already exists.", environmentConfig.name().toString())); throw haltBecauseEntityAlreadyExists(jsonWriter(environmentConfig), "environment", environmentConfig.name().toString()); }
jobCreationTimeMap.put(plan.getJobId(), timeProvider.currentTimeMillis()); if (elasticAgentPluginRegistry.has(plan.getElasticProfile().getPluginId())) { String environment = environmentConfigService.envForPipeline(plan.getPipelineName()); createAgentQueue.post(new CreateAgentMessage(goConfigService.serverConfig().getAgentAutoRegisterKey(), environment, plan.getElasticProfile(), plan.getIdentifier()), messageTimeToLive); serverHealthService.removeByScope(HealthStateScope.forJob(plan.getIdentifier().getPipelineName(), plan.getIdentifier().getStageName(), plan.getIdentifier().getBuildName()));
private AgentViewModel toAgentViewModel(AgentInstance instance) { return new AgentViewModel(instance, environmentConfigService.environmentsFor(instance.getUuid())); }
public String index(Request request, Response response) throws IOException { List<EnvironmentConfig> environmentViewModelList = environmentConfigService.getAllMergedEnvironments(); setEtagHeader(response, calculateEtag(environmentViewModelList)); return writerForTopLevelObject(request, response, outputWriter -> EnvironmentsRepresenter.toJSON(outputWriter, environmentViewModelList)); }
@Override public Consumer<OutputWriter> jsonWriter(AgentInstance agentInstance) { return outputWriter -> AgentRepresenter.toJSON(outputWriter, agentInstance, environmentConfigService.environmentsFor(agentInstance.getUuid()), securityService, currentUsername()); }
public String show(Request request, Response response) throws IOException { final AgentInstance agentInstance = fetchEntityFromConfig(request.params("uuid")); return writerForTopLevelObject(request, response, outputWriter -> AgentRepresenter.toJSON(outputWriter, agentInstance, environmentConfigService.environmentsFor(request.params("uuid")), securityService, currentUsername())); }