use of io.jenkins.blueocean.rest.hal.Link in project blueocean-plugin by jenkinsci.
the class AbstractBitbucketScm method getOrganizations.
@Override
public Container<ScmOrganization> getOrganizations() {
User authenticatedUser = getAuthenticatedUser();
StaplerRequest request = Stapler.getCurrentRequest();
Objects.requireNonNull(request, "This request must be made in HTTP context");
String credentialId = BitbucketCredentialUtils.computeCredentialId(getCredentialIdFromRequest(request), getId(), getUri());
List<ErrorMessage.Error> errors = new ArrayList<>();
StandardUsernamePasswordCredentials credential = null;
if (credentialId == null) {
errors.add(new ErrorMessage.Error("credentialId", ErrorMessage.Error.ErrorCodes.MISSING.toString(), "Missing credential id. It must be provided either as HTTP header: " + X_CREDENTIAL_ID + " or as query parameter 'credentialId'"));
} else {
credential = CredentialsUtils.findCredential(credentialId, StandardUsernamePasswordCredentials.class, new BlueOceanDomainRequirement());
if (credential == null) {
errors.add(new ErrorMessage.Error("credentialId", ErrorMessage.Error.ErrorCodes.INVALID.toString(), String.format("credentialId: %s not found in user %s's credential store", credentialId, authenticatedUser.getId())));
}
}
String apiUrl = request.getParameter("apiUrl");
if (StringUtils.isBlank(apiUrl)) {
errors.add(new ErrorMessage.Error("apiUrl", ErrorMessage.Error.ErrorCodes.MISSING.toString(), "apiUrl is required parameter"));
}
if (!errors.isEmpty()) {
throw new ServiceException.BadRequestException(new ErrorMessage(400, "Failed to return Bitbucket organizations").addAll(errors));
} else {
apiUrl = normalizeApiUrl(apiUrl);
BitbucketApiFactory apiFactory = BitbucketApiFactory.resolve(this.getId());
if (apiFactory == null) {
throw new ServiceException.UnexpectedErrorException("BitbucketApiFactory to handle apiUrl " + apiUrl + " not found");
}
Objects.requireNonNull(credential);
final BitbucketApi api = apiFactory.create(apiUrl, credential);
return new Container<ScmOrganization>() {
@Override
public ScmOrganization get(String name) {
return new BitbucketOrg(api.getOrg(name), api, getLink());
}
@Override
public Link getLink() {
return AbstractBitbucketScm.this.getLink().rel("organizations");
}
@Override
public Iterator<ScmOrganization> iterator() {
return iterator(0, 100);
}
@Override
public Iterator<ScmOrganization> iterator(int start, int limit) {
if (limit <= 0) {
limit = PagedResponse.DEFAULT_LIMIT;
}
if (start < 0) {
start = 0;
}
int page = (start / limit) + 1;
return api.getOrgs(page, limit).getValues().stream().map(input -> {
if (input != null) {
return (ScmOrganization) new BitbucketOrg(input, api, getLink());
}
return null;
}).iterator();
}
};
}
}
use of io.jenkins.blueocean.rest.hal.Link in project blueocean-plugin by jenkinsci.
the class PipelineNodeGraphVisitor method getPipelineNodeSteps.
@Override
public List<BluePipelineStep> getPipelineNodeSteps(Link parent) {
FlowExecution execution = run.getExecution();
if (execution == null) {
return Collections.emptyList();
}
PipelineStepVisitor visitor = new PipelineStepVisitor(run, null);
ForkScanner.visitSimpleChunks(execution.getCurrentHeads(), visitor, new StageChunkFinder());
return visitor.getSteps().stream().map(node -> new PipelineStepImpl(node, parent)).collect(Collectors.toList());
}
use of io.jenkins.blueocean.rest.hal.Link in project blueocean-plugin by jenkinsci.
the class PipelineNodeTest method sequentialParallelStagesLongRun.
@Ignore("Fails on ci.jenkins.io but not locally. Reasons unclear. Likely a timing issue.")
@Test
public void sequentialParallelStagesLongRun() throws Exception {
WorkflowJob p = createWorkflowJobWithJenkinsfile(getClass(), "sequential_parallel_stages_long_run_time.jenkinsfile");
Slave s = j.createOnlineSlave();
s.setNumExecutors(3);
WorkflowRun run = p.scheduleBuild2(0).waitForStart();
j.waitForCompletion(run);
List<String> watchedStages = Arrays.asList("first-sequential-stage", "second-sequential-stage", "third-sequential-stage");
run = p.scheduleBuild2(0).waitForStart();
Thread.sleep(1000);
long loopCount = 0;
while (run.isBuilding()) {
PipelineNodeContainerImpl pipelineNodeContainer = new PipelineNodeContainerImpl(run, new Link("foo"));
List<BluePipelineNode> nodes = pipelineNodeContainer.getNodes();
for (BluePipelineNode node : nodes) {
if (StringUtils.isEmpty(node.getFirstParent()) && watchedStages.contains(node.getDisplayName())) {
LOGGER.error("node {} has getFirstParent null", node);
fail("node with getFirstParent null:" + node);
}
// we try to find edges with id for a non existing node in the list
List<BluePipelineNode.Edge> emptyEdges = node.getEdges().stream().filter(edge -> !nodes.stream().filter(bluePipelineNode -> bluePipelineNode.getId().equals(edge.getId())).findFirst().isPresent()).collect(Collectors.toList());
if (!emptyEdges.isEmpty()) {
// TODO remove this weird if but it's only to have breakpoint in IDE
assertTrue("edges with unknown nodes" + nodes, !emptyEdges.isEmpty());
}
}
LOGGER.debug("nodes size {}", nodes.size());
if (nodes.size() != 9) {
LOGGER.info("loop: " + loopCount + ", nodes size {}", nodes.size());
LOGGER.info("nodes != 9 {}", nodes);
fail("nodes != 9: " + nodes);
}
Thread.sleep(100);
}
}
use of io.jenkins.blueocean.rest.hal.Link in project blueocean-plugin by jenkinsci.
the class PipelineNodeTest method checkConsistencyWhileBuilding.
private String checkConsistencyWhileBuilding(String jenkinsFileName) throws Exception {
/*
Run a complex pipeline to completion, then start a new build and inspect it while it's running, to exercise
the code that merges incomplete runs with previous builds to generate a complete graph
*/
WorkflowJob p = createWorkflowJobWithJenkinsfile(getClass(), jenkinsFileName);
// Do an initial run, collect the nodes
final WorkflowRun run1 = p.scheduleBuild2(0).waitForStart();
j.waitForCompletion(run1);
final List<BluePipelineNode> completeNodes = new PipelineNodeContainerImpl(run1, new Link("foo")).getNodes();
final String completeNodeNames = completeNodes.stream().map(BluePipelineStep::getDisplayName).sorted().collect(Collectors.joining(", "));
// Start another build...
final WorkflowRun run2 = p.scheduleBuild2(0).waitForStart();
// ... then watch while it runs, checking for the same graph nodes
int loopCount = 0;
do {
Thread.sleep(1000);
List<BluePipelineNode> runningNodes = new PipelineNodeContainerImpl(run2, new Link("foo")).getNodes();
String runningNodeNames = runningNodes.stream().map(BluePipelineStep::getDisplayName).sorted().collect(Collectors.joining(", "));
assertEquals("running node names", completeNodeNames, runningNodeNames);
loopCount++;
} while (run2.isBuilding());
// Sanity check, make sure we're *actually* checking stuff.
assertTrue("Checked multiple times while building", loopCount > 5);
// So caller can do any additional checks
return completeNodeNames;
}
use of io.jenkins.blueocean.rest.hal.Link in project blueocean-plugin by jenkinsci.
the class OrganizationFolderTest method mockOrganization.
static BlueOrganization mockOrganization() {
BlueOrganization organization = mock(BlueOrganization.class);
when(organization.getName()).thenReturn("jenkins");
when(organization.getLink()).thenReturn(new Link("/blue/rest/organizations/jenkins/"));
return organization;
}
Aggregations