use of com.thoughtworks.go.domain.JobPlan in project gocd by gocd.
the class LongWorkCreator method getWork.
public Work getWork() {
try {
CruiseConfig config = GoConfigMother.pipelineHavingJob(PIPELINE_NAME, STAGE_NAME, JOB_PLAN_NAME, ARTIFACT_FILE.getAbsolutePath(), ARTIFACT_FOLDER.getAbsolutePath());
BuildCause buildCause = BuildCause.createWithEmptyModifications();
builder = new ArrayList<>();
builder.add(new SleepBuilder());
JobPlan instance = toBuildInstance(config);
BuildAssignment buildAssignment = BuildAssignment.create(instance, buildCause, builder, new File(CruiseConfig.WORKING_BASE_DIR + PIPELINE_NAME));
return new BuildWork(buildAssignment);
} catch (Exception e) {
throw bomb(e);
}
}
use of com.thoughtworks.go.domain.JobPlan in project gocd by gocd.
the class JobPlanXmlRepresenter method populateJob.
public void populateJob(ElementBuilder builder, XmlWriterContext ctx, WaitingJobPlan waitingJobPlan) {
JobPlan jobPlan = waitingJobPlan.jobPlan();
builder.attr("name", jobPlan.getName()).link(ctx.jobXmlLink(jobPlan.getIdentifier()), "self").link(ctx.jobDetailsLink(jobPlan.getIdentifier()), "alternate", jobPlan.getName() + " Job Detail", "text/html").textNode("buildLocator", jobPlan.getIdentifier().buildLocator());
if (isNotBlank(waitingJobPlan.envName())) {
builder.textNode("environment", waitingJobPlan.envName());
}
if (!jobPlan.getResources().isEmpty()) {
builder.node("resources", rb -> jobPlan.getResources().forEach(resource -> {
rb.cdataNode("resource", resource.getName());
}));
}
if (!jobPlan.getVariables().isEmpty()) {
builder.node("environmentVariables", eb -> jobPlan.getVariables().forEach(variable -> {
eb.node("variable", vb -> vb.attr("name", variable.getName()).text(variable.getDisplayValue()));
}));
}
}
use of com.thoughtworks.go.domain.JobPlan in project gocd by gocd.
the class ElasticAgentPluginService method getAgentStatusReport.
public String getAgentStatusReport(String pluginId, JobIdentifier jobIdentifier, String elasticAgentId) throws Exception {
final ElasticAgentPluginInfo pluginInfo = elasticAgentMetadataStore.getPluginInfo(pluginId);
if (pluginInfo == null) {
throw new RecordNotFoundException(format("Plugin with id: '%s' is not found.", pluginId));
}
if (pluginInfo.getCapabilities().supportsAgentStatusReport()) {
JobPlan jobPlan = jobInstanceSqlMapDao.loadPlan(jobIdentifier.getId());
if (jobPlan != null) {
ClusterProfile clusterProfile = jobPlan.getClusterProfile();
Map<String, String> clusterProfileConfigurations = emptyMap();
if (clusterProfile != null) {
secretParamResolver.resolve(clusterProfile);
clusterProfileConfigurations = clusterProfile.getConfigurationAsMap(true, true);
}
return elasticAgentPluginRegistry.getAgentStatusReport(pluginId, jobIdentifier, elasticAgentId, clusterProfileConfigurations);
}
throw new Exception(format("Could not fetch agent status report for agent %s as either the job running on the agent has been completed or the agent has been terminated.", elasticAgentId));
}
throw new UnsupportedOperationException("Plugin does not support agent status report.");
}
use of com.thoughtworks.go.domain.JobPlan in project gocd by gocd.
the class ElasticAgentPluginService method createAgentsFor.
public void createAgentsFor(List<JobPlan> old, List<JobPlan> newPlan) {
Collection<JobPlan> starvingJobs = new ArrayList<>();
for (JobPlan jobPlan : newPlan) {
if (jobPlan.requiresElasticAgent()) {
if (!jobCreationTimeMap.containsKey(jobPlan.getJobId())) {
continue;
}
long lastTryTime = jobCreationTimeMap.get(jobPlan.getJobId());
if ((timeProvider.currentTimeMillis() - lastTryTime) >= goConfigService.elasticJobStarvationThreshold()) {
starvingJobs.add(jobPlan);
}
}
}
ArrayList<JobPlan> jobsThatRequireAgent = new ArrayList<>();
jobsThatRequireAgent.addAll(Sets.difference(new HashSet<>(newPlan), new HashSet<>(old)));
jobsThatRequireAgent.addAll(starvingJobs);
List<JobPlan> plansThatRequireElasticAgent = jobsThatRequireAgent.stream().filter(isElasticAgent()).collect(toList());
// messageTimeToLive is lesser than the starvation threshold to ensure there are no duplicate create agent message
long messageTimeToLive = goConfigService.elasticJobStarvationThreshold() - 10000;
for (JobPlan plan : plansThatRequireElasticAgent) {
jobCreationTimeMap.put(plan.getJobId(), timeProvider.currentTimeMillis());
ElasticProfile elasticProfile = plan.getElasticProfile();
ClusterProfile clusterProfile = plan.getClusterProfile();
JobIdentifier jobIdentifier = plan.getIdentifier();
if (clusterProfile == null) {
String cancellationMessage = "\nThis job was cancelled by GoCD. The version of your GoCD server requires elastic profiles to be associated with a cluster(required from Version 19.3.0). " + "This job is configured to run on an Elastic Agent, but the associated elastic profile does not have information about the cluster. \n\n" + "The possible reason for the missing cluster information on the elastic profile could be, an upgrade of the GoCD server to a version >= 19.3.0 before the completion of the job.\n\n" + "A re-run of this job should fix this issue.";
logToJobConsole(jobIdentifier, cancellationMessage);
scheduleService.cancelJob(jobIdentifier);
} else if (elasticAgentPluginRegistry.has(clusterProfile.getPluginId())) {
String environment = environmentConfigService.envForPipeline(plan.getPipelineName());
try {
resolveSecrets(clusterProfile, elasticProfile);
createAgentQueue.post(new CreateAgentMessage(ephemeralAutoRegisterKeyService.autoRegisterKey(), environment, elasticProfile, clusterProfile, jobIdentifier), messageTimeToLive);
serverHealthService.removeByScope(scopeForJob(jobIdentifier));
} catch (RulesViolationException | SecretResolutionFailureException e) {
JobInstance jobInstance = jobInstanceSqlMapDao.buildById(plan.getJobId());
String failureMessage = format("\nThis job was failed by GoCD. This job is configured to run on an elastic agent, there were errors while resolving secrets for the the associated elastic configurations.\nReasons: %s", e.getMessage());
logToJobConsole(jobIdentifier, failureMessage);
scheduleService.failJob(jobInstance);
jobStatusTopic.post(new JobStatusMessage(jobIdentifier, jobInstance.getState(), plan.getAgentUuid()));
}
} else {
String jobConfigIdentifier = jobIdentifier.jobConfigIdentifier().toString();
String description = format("Plugin [%s] associated with %s is missing. Either the plugin is not " + "installed or could not be registered. Please check plugins tab " + "and server logs for more details.", clusterProfile.getPluginId(), jobConfigIdentifier);
serverHealthService.update(error(format("Unable to find agent for %s", jobConfigIdentifier), description, general(scopeForJob(jobIdentifier))));
LOGGER.error(description);
}
}
}
use of com.thoughtworks.go.domain.JobPlan in project gocd by gocd.
the class JobXmlViewModelTest method setUp.
@Before
public void setUp() {
xmlWriterContext = mock(XmlWriterContext.class);
jobPlan = mock(JobPlan.class);
defaultJob = JobInstanceMother.completed("defaultJob");
when(xmlWriterContext.planFor(defaultJob.getIdentifier())).thenReturn(jobPlan);
when(xmlWriterContext.propertiesForJob(defaultJob.getId())).thenReturn(new Properties());
jobXmlViewModel = new JobXmlViewModel(defaultJob);
}
Aggregations