io.fabric8.openshift.api.model.Build Java Examples
The following examples show how to use
io.fabric8.openshift.api.model.Build.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: KubernetesResourceUtil.java From jkube with Eclipse Public License 2.0 | 6 votes |
public static String getBuildStatusReason(Build build) { if (build != null && build.getStatus() != null) { String reason = build.getStatus().getReason(); String phase = build.getStatus().getPhase(); if (StringUtils.isNotBlank(phase)) { if (StringUtils.isNotBlank(reason)) { return phase + ": " + reason; } else { return phase; } } else { return StringUtils.defaultIfEmpty(reason, ""); } } return ""; }
Example #2
Source File: HandlersTest.java From kubernetes-client with Apache License 2.0 | 6 votes |
@Test void checkHandlers() { checkHandler(new BuildConfig(), new BuildConfigHandler()); checkHandler(new Build(), new BuildHandler()); checkHandler(new DeploymentConfig(), new DeploymentConfigHandler()); checkHandler(new Group(), new GroupHandler()); checkHandler(new Identity(), new IdentityHandler()); checkHandler(new Image(), new ImageHandler()); checkHandler(new ImageStream(), new ImageStreamHandler()); checkHandler(new ImageStreamTag(), new ImageStreamTagHandler()); checkHandler(new NetNamespace(), new NetNamespaceHandler()); checkHandler(new OAuthAccessToken(), new OAuthAccessTokenHandler()); checkHandler(new OAuthAuthorizeToken(), new OAuthAuthorizeTokenHandler()); checkHandler(new OAuthClient(), new OAuthClientHandler()); checkHandler(new Project(), new ProjectHandler()); checkHandler(new Route(), new RouteHandler()); checkHandler(new SecurityContextConstraints(), new SecurityContextConstraintsHandler()); checkHandler(new User(), new UserHandler()); }
Example #3
Source File: BuildOperationsImpl.java From kubernetes-client with Apache License 2.0 | 6 votes |
public BuildOperationsImpl(BuildOperationContext context) { super(context.withApiGroupName(BUILD) .withPlural("builds")); this.type = Build.class; this.listType = BuildList.class; this.doneableType = DoneableBuild.class; this.in = context.getIn(); this.out = context.getOut(); this.err = context.getErr(); this.inPipe = context.getInPipe(); this.outPipe = context.getOutPipe(); this.errPipe = context.getErrPipe(); this.withTTY = context.isTty(); this.withTerminatedStatus = context.isTerminatedStatus(); this.withTimestamps = context.isTimestamps(); this.sinceTimestamp = context.getSinceTimestamp(); this.sinceSeconds = context.getSinceSeconds(); this.withTailingLines = context.getTailingLines(); this.withPrettyOutput = context.isPrettyOutput(); this.version = context.getVersion(); this.limitBytes = context.getLimitBytes(); }
Example #4
Source File: BuildConfigOperationsImpl.java From kubernetes-client with Apache License 2.0 | 6 votes |
private void deleteBuilds() { if (getName() == null) { return; } String buildConfigLabelValue = getName().substring(0, Math.min(getName().length(), 63)); BuildList matchingBuilds = new BuildOperationsImpl(client, (OpenShiftConfig) config).inNamespace(namespace).withLabel(BUILD_CONFIG_LABEL, buildConfigLabelValue).list(); if (matchingBuilds.getItems() != null) { for (Build matchingBuild : matchingBuilds.getItems()) { if (matchingBuild.getMetadata() != null && matchingBuild.getMetadata().getAnnotations() != null && getName().equals(matchingBuild.getMetadata().getAnnotations().get(BUILD_CONFIG_ANNOTATION))) { new BuildOperationsImpl(client, (OpenShiftConfig) config).inNamespace(matchingBuild.getMetadata().getNamespace()).withName(matchingBuild.getMetadata().getName()).delete(); } } } }
Example #5
Source File: OpenShiftServiceImpl.java From syndesis with Apache License 2.0 | 6 votes |
private Build waitForBuild(Build r, long timeout, TimeUnit timeUnit) throws InterruptedException { long end = System.currentTimeMillis() + timeUnit.toMillis(timeout); Build next = r; int retriesLeft = config.getMaximumRetries(); while ( System.currentTimeMillis() < end) { if (next.getStatus() != null && ("Complete".equals(next.getStatus().getPhase()) || "Failed".equals(next.getStatus().getPhase()))) { return next; } try { next = openShiftClient.builds().inNamespace(next.getMetadata().getNamespace()).withName(next.getMetadata().getName()).get(); } catch (KubernetesClientException e) { checkRetryPolicy(e, retriesLeft--); } Thread.sleep(config.getPollingInterval()); } throw SyndesisServerException.launderThrowable(new TimeoutException("Timed out waiting for build completion.")); }
Example #6
Source File: KubernetesHelper.java From jkube with Eclipse Public License 2.0 | 6 votes |
public static String getBuildStatusReason(Build build) { if (build != null && build.getStatus() != null) { String reason = build.getStatus().getReason(); String phase = build.getStatus().getPhase(); if (StringUtils.isNotBlank(phase)) { if (StringUtils.isNotBlank(reason)) { return phase + ": " + reason; } else { return phase; } } else { return StringUtils.defaultIfEmpty(reason, ""); } } return ""; }
Example #7
Source File: OpenshiftBuildService.java From jkube with Eclipse Public License 2.0 | 6 votes |
private void logBuildFailure(OpenShiftClient client, String buildName) throws JKubeServiceException { try { List<Build> builds = client.builds().inNamespace(client.getNamespace()).list().getItems(); for(Build build : builds) { if(build.getMetadata().getName().contains(buildName)) { log.error(build.getMetadata().getName() + "\t" + "\t" + build.getStatus().getReason() + "\t" + build.getStatus().getMessage()); throw new JKubeServiceException("Unable to build the image using the OpenShift build service", new KubernetesClientException(build.getStatus().getReason() + " " + build.getStatus().getMessage())); } } log.error("Also, check cluster events via `oc get events` to see what could have possibly gone wrong"); } catch (KubernetesClientException clientException) { Status status = clientException.getStatus(); if (status != null) log.error("OpenShift Error: [%d] %s", status.getCode(), status.getMessage()); } }
Example #8
Source File: OpenshiftBuildService.java From jkube with Eclipse Public License 2.0 | 6 votes |
private Build startBuild(OpenShiftClient client, File dockerTar, String buildName) { log.info("Starting Build %s", buildName); try { return client.buildConfigs().withName(buildName) .instantiateBinary() .fromFile(dockerTar); } catch (KubernetesClientException exp) { Status status = exp.getStatus(); if (status != null) { log.error("OpenShift Error: [%d %s] [%s] %s", status.getCode(), status.getStatus(), status.getReason(), status.getMessage()); } if (exp.getCause() instanceof IOException && exp.getCause().getMessage().contains("Stream Closed")) { log.error("Build for %s failed: %s", buildName, exp.getCause().getMessage()); logBuildFailedDetails(client, buildName); } throw exp; } }
Example #9
Source File: OpenshiftExtension.java From dekorate with Apache License 2.0 | 5 votes |
/** * Performs the binary build of the specified {@link BuildConfig} with the given binary input. * @param buildConfig The build config. * @param binaryFile The binary file. */ private void binaryBuild(OpenShiftClient client, BuildConfig buildConfig, File binaryFile) { LOGGER.info("Running binary build:"+buildConfig.getMetadata().getName()+ " for:" +binaryFile.getAbsolutePath()); Build build = client.buildConfigs().withName(buildConfig.getMetadata().getName()).instantiateBinary().fromFile(binaryFile); try (BufferedReader reader = new BufferedReader(client.builds().withName(build.getMetadata().getName()).getLogReader())) { for (String line = reader.readLine(); line != null; line = reader.readLine()) { System.out.println(line); } } catch (IOException e) { throw DekorateException.launderThrowable(e); } }
Example #10
Source File: TeiidOpenShiftClient.java From syndesis with Apache License 2.0 | 5 votes |
private static Build createBuild(OpenShiftClient client, String namespace, BuildConfig config, InputStream tarInputStream) { return client.buildConfigs() .inNamespace(namespace) .withName(config.getMetadata().getName()) .instantiateBinary().fromInputStream(tarInputStream); }
Example #11
Source File: TeiidOpenShiftClient.java From syndesis with Apache License 2.0 | 5 votes |
private static Build findBuildWithNumber(long number, BuildList buildList) { for (Build b : buildList.getItems()) { String buildNumber = b.getMetadata().getAnnotations().get("openshift.io/build.number"); if (buildNumber != null && Long.parseLong(buildNumber) == number) { return b; } } return buildList.getItems().get(0); }
Example #12
Source File: PublishingStateMonitor.java From syndesis with Apache License 2.0 | 5 votes |
protected Optional<Build> getBuild(String integrationId, String version) { return client.builds() .withLabel(OpenShiftService.INTEGRATION_ID_LABEL, integrationId) .withLabel(OpenShiftService.DEPLOYMENT_VERSION_LABEL, version) .list() .getItems().stream().findFirst(); }
Example #13
Source File: BuildConfigOperationsImpl.java From kubernetes-client with Apache License 2.0 | 5 votes |
@Override public Build fromFile(final File file) { if (!file.exists()) { throw new IllegalArgumentException("Can't instantiate binary build from the specified file. The file does not exists"); } try (InputStream is = new FileInputStream(file)) { // Use a length to prevent chunked encoding with OkHttp, which in turn // doesn't work with 'Expect: 100-continue' negotiation with the OpenShift API server return fromInputStream(is, file.length()); } catch (Throwable t) { throw KubernetesClientException.launderThrowable(t); } }
Example #14
Source File: BuildConfigOperationsImpl.java From kubernetes-client with Apache License 2.0 | 5 votes |
@Override public Build instantiate(BuildRequest request) { try { updateApiVersion(request); URL instantiationUrl = new URL(URLUtils.join(getResourceUrl().toString(), "instantiate")); RequestBody requestBody = RequestBody.create(JSON, BaseOperation.JSON_MAPPER.writer().writeValueAsString(request)); Request.Builder requestBuilder = new Request.Builder().post(requestBody).url(instantiationUrl); return handleResponse(requestBuilder, Build.class); } catch (Exception e) { throw KubernetesClientException.launderThrowable(e); } }
Example #15
Source File: BuildConfigOperationsImpl.java From kubernetes-client with Apache License 2.0 | 4 votes |
@Override public AsFileTimeoutInputStreamable<Build> withMessage(String message) { return new BuildConfigOperationsImpl(getContext().withMessage(message)); }
Example #16
Source File: KubernetesResourceUtil.java From jkube with Eclipse Public License 2.0 | 4 votes |
public static String getBuildStatusPhase(Build build) { if (build != null && build.getStatus() != null) { return build.getStatus().getPhase(); } return null; }
Example #17
Source File: BuildConfigOperationsImpl.java From kubernetes-client with Apache License 2.0 | 4 votes |
@Override public AuthorEmailable<MessageAsFileTimeoutInputStreamable<Build>> withAuthorName(String authorName) { return new BuildConfigOperationsImpl(getContext().withAuthorName(authorName)); }
Example #18
Source File: BuildConfigOperationsImpl.java From kubernetes-client with Apache License 2.0 | 4 votes |
@Override public CommitterEmailable<AuthorMessageAsFileTimeoutInputStreamable<Build>> withCommitterName(String committerName) { return new BuildConfigOperationsImpl(getContext().withCommitterName(committerName)); }
Example #19
Source File: BuildConfigOperationsImpl.java From kubernetes-client with Apache License 2.0 | 4 votes |
@Override public InputStreamable<Build> withTimeout(long timeout, TimeUnit unit) { return new BuildConfigOperationsImpl(getContext().withTimeout(timeout).withTimeoutUnit(unit)); }
Example #20
Source File: BuildConfigOperationsImpl.java From kubernetes-client with Apache License 2.0 | 4 votes |
@Override public InputStreamable<Build> withTimeoutInMillis(long timeoutInMillis) { return withTimeout(timeoutInMillis, TimeUnit.MILLISECONDS); }
Example #21
Source File: DefaultOpenShiftClient.java From kubernetes-client with Apache License 2.0 | 4 votes |
@Override public MixedOperation<Build, BuildList, DoneableBuild, BuildResource<Build, DoneableBuild, String, LogWatch>> builds() { return new BuildOperationsImpl(httpClient, OpenShiftConfig.wrap(getConfiguration())); }
Example #22
Source File: DefaultOpenShiftClient.java From kubernetes-client with Apache License 2.0 | 4 votes |
@Override public MixedOperation<BuildConfig, BuildConfigList, DoneableBuildConfig, BuildConfigResource<BuildConfig, DoneableBuildConfig, Void, Build>> buildConfigs() { return new BuildConfigOperationsImpl(httpClient, OpenShiftConfig.wrap(getConfiguration())); }
Example #23
Source File: KubernetesHelper.java From jkube with Eclipse Public License 2.0 | 4 votes |
public static String getBuildStatusPhase(Build build) { if (build != null && build.getStatus() != null) { return build.getStatus().getPhase(); } return null; }
Example #24
Source File: BuildConfigOperationsImpl.java From kubernetes-client with Apache License 2.0 | 4 votes |
@Override public AuthorMessageAsFileTimeoutInputStreamable<Build> withCommitterEmail(String committerEmail) { return new BuildConfigOperationsImpl(getContext().withCommitterEmail(committerEmail)); }
Example #25
Source File: BuildConfigOperationsImpl.java From kubernetes-client with Apache License 2.0 | 4 votes |
@Override public MessageAsFileTimeoutInputStreamable<Build> withAuthorEmail(String email) { return new BuildConfigOperationsImpl(getContext().withAuthorEmail(email)); }
Example #26
Source File: BuildConfigOperationsImpl.java From kubernetes-client with Apache License 2.0 | 4 votes |
@Override public TimeoutInputStreamable<Build> asFile(String fileName) { return new BuildConfigOperationsImpl(getContext().withAsFile(fileName)); }
Example #27
Source File: BuildConfigOperationsImpl.java From kubernetes-client with Apache License 2.0 | 4 votes |
@Override public Build fromInputStream(final InputStream inputStream) { return fromInputStream(inputStream, -1L); }
Example #28
Source File: OpenshiftBuildService.java From jkube with Eclipse Public License 2.0 | 4 votes |
private void waitForOpenShiftBuildToComplete(OpenShiftClient client, Build build) throws IOException { final CountDownLatch latch = new CountDownLatch(1); final CountDownLatch logTerminateLatch = new CountDownLatch(1); final String buildName = KubernetesHelper.getName(build); final AtomicReference<Build> buildHolder = new AtomicReference<>(); // Don't query for logs directly, Watch over the build pod: waitUntilPodIsReady(buildName + "-build", 120, log); log.info("Waiting for build " + buildName + " to complete..."); try (LogWatch logWatch = client.pods().withName(buildName + "-build").watchLog()) { KubernetesHelper.printLogsAsync(logWatch, "Failed to tail build log", logTerminateLatch, log); Watcher<Build> buildWatcher = getBuildWatcher(latch, buildName, buildHolder); try (Watch watcher = client.builds().withName(buildName).watch(buildWatcher)) { // Check if the build is already finished to avoid waiting indefinitely Build lastBuild = client.builds().withName(buildName).get(); if (OpenshiftHelper.isFinished(KubernetesHelper.getBuildStatusPhase(lastBuild))) { log.debug("Build %s is already finished", buildName); buildHolder.set(lastBuild); latch.countDown(); } waitUntilBuildFinished(latch); logTerminateLatch.countDown(); build = buildHolder.get(); if (build == null) { log.debug("Build watcher on %s was closed prematurely", buildName); build = client.builds().withName(buildName).get(); } String status = KubernetesHelper.getBuildStatusPhase(build); if (OpenshiftHelper.isFailed(status) || OpenshiftHelper.isCancelled(status)) { throw new IOException("OpenShift Build " + buildName + " failed: " + KubernetesHelper.getBuildStatusReason(build)); } if (!OpenshiftHelper.isFinished(status)) { log.warn("Could not wait for the completion of build %s. It may be may be still running (status=%s)", buildName, status); } else { log.info("Build %s in status %s", buildName, status); } } } }
Example #29
Source File: BuildConfigOperationsImpl.java From kubernetes-client with Apache License 2.0 | 4 votes |
@Override public CommitterAuthorMessageAsFileTimeoutInputStreamable<Build> instantiateBinary() { return new BuildConfigOperationsImpl(getContext()); }
Example #30
Source File: BuildConfigOperator.java From strimzi-kafka-operator with Apache License 2.0 | 4 votes |
@Override protected MixedOperation<BuildConfig, BuildConfigList, DoneableBuildConfig, BuildConfigResource<BuildConfig, DoneableBuildConfig, Void, Build>> operation() { return client.buildConfigs(); }