/** * Lookup namespace that is already defined in the current build. * @return The {@link NamespaceAction}. */ protected NamespaceAction getNamespaceAction() { try { return new NamespaceAction(getContext().get(Run.class)); } catch (Throwable t) { return null; } } protected URL toURL(String url) {
/** * Lookup namespace that is already defined in the current build. * @return The {@link NamespaceAction}. */ protected NamespaceAction getNamespaceAction() { try { return new NamespaceAction(getContext().get(Run.class)); } catch (Throwable t) { return null; } }
/** * Lookup namespace that is already defined in the current build. * @return The {@link NamespaceAction}. */ protected NamespaceAction getNamespaceAction() { try { return new NamespaceAction(getContext().get(Run.class)); } catch (Throwable t) { return null; } } protected URL toURL(String url) {
/** * Lookup namespace that is already defined in the current build. * @return The {@link NamespaceAction}. */ protected NamespaceAction getNamespaceAction() { try { return new NamespaceAction(getContext().get(Run.class)); } catch (Throwable t) { return null; } }
@Deprecated public void push(String namespace) throws IOException { if (run == null) { LOGGER.warning("run is null, cannot push"); return; } synchronized (run) { BulkChange bc = new BulkChange(run); try { NamespaceAction action = run.getAction(NamespaceAction.class); if (action == null) { action = new NamespaceAction(run); run.addAction(action); } action.stack.push(namespace); bc.commit(); } finally { bc.abort(); } } }
@Deprecated @SuppressFBWarnings("DLS_DEAD_LOCAL_STORE") public String pop() throws IOException { if (run == null) { LOGGER.warning("run is null, cannot pop"); return null; } synchronized (run) { BulkChange bc = new BulkChange(run); try { NamespaceAction action = run.getAction(NamespaceAction.class); if (action == null) { action = new NamespaceAction(run); run.addAction(action); } String namespace = action.stack.pop(); bc.commit(); return namespace; } finally { bc.abort(); return null; } } }
@Override public void stop(Throwable cause) throws Exception { if (configuration.isNamespaceDestroyEnabled()) { namespaceService.destroy(namespace); } String ns = new NamespaceAction(getContext().get(Run.class)).pop(); }
@Override public void stop(Throwable cause) throws Exception { if (configuration.isNamespaceDestroyEnabled()) { namespaceService.destroy(namespace); } String ns = new NamespaceAction(getContext().get(Run.class)).pop(); }
@Override protected String run() throws Exception { String namespace = null; try { FilePath workspace = getContext().get(FilePath.class); namespace = workspace.child(Config.KUBERNETES_NAMESPACE_PATH).readToString(); if (Utils.isNotNullOrEmpty(namespace)) { return namespace; } } catch (Throwable t) { //it might be executed outside of a `node` block in which case, we want to ignore. } NamespaceAction namespaceAction = new NamespaceAction(getContext().get(Run.class)); namespace = namespaceAction.getNamespace(); if (Utils.isNotNullOrEmpty(namespace)) { return namespace; } return step.getFallbackNamespace(); } }
@Override protected String run() throws Exception { String namespace = null; try { FilePath workspace = getContext().get(FilePath.class); namespace = workspace.child(Config.KUBERNETES_NAMESPACE_PATH).readToString(); if (Utils.isNotNullOrEmpty(namespace)) { return namespace; } } catch (Throwable t) { //it might be executed outside of a `node` block in which case, we want to ignore. } NamespaceAction namespaceAction = new NamespaceAction(getContext().get(Run.class)); namespace = namespaceAction.getNamespace(); if (Utils.isNotNullOrEmpty(namespace)) { return namespace; } return step.getFallbackNamespace(); } }
@Override public boolean start() throws Exception { TaskListener listener = getContext().get(TaskListener.class); NamespaceAction namespaceAction = new NamespaceAction(getContext().get(Run.class)); sessionId = generateSessionId(); namespace = generateNamespaceId(step.getName(), step.getPrefix(), sessionId); client = getKubernetesClient(); isOpenshift = client.isAdaptable(OpenShiftClient.class); configuration = new DefaultConfigurationBuilder() .withNamespace(namespace) .withNamespaceLazyCreateEnabled(step.isNamespaceLazyCreateEnabled()) .withNamespaceDestroyEnabled(step.isNamespaceDestroyEnabled()) .withMasterUrl(client.getMasterUrl()) .build(); StreamLogger logger = new StreamLogger(listener.getLogger()); LabelProvider labelProvider = new MapLabelProvider(step.getLabels()); namespaceService = isOpenshift ? new OpenshiftNamespaceService.ImmutableOpenshiftNamespaceService(client, configuration, labelProvider, logger) : new DefaultNamespaceService.ImmutableNamespaceService(client, configuration, labelProvider, logger); if (!namespaceService.exists(namespace) && configuration.isNamespaceLazyCreateEnabled()) { namespaceService.create(namespace); } namespaceAction.push(namespace); getContext().newBodyInvoker(). withContext(EnvironmentExpander.merge(getContext().get(EnvironmentExpander.class), new NamespaceExpander(namespace))). withCallback(new NamespaceDestructionCallback(namespace, configuration, namespaceService, namespaceAction)). start(); return false; }
@Override public boolean start() throws Exception { TaskListener listener = getContext().get(TaskListener.class); NamespaceAction namespaceAction = new NamespaceAction(getContext().get(Run.class)); sessionId = generateSessionId(); namespace = generateNamespaceId(step.getName(), step.getPrefix(), sessionId); client = getKubernetesClient(); isOpenshift = client.isAdaptable(OpenShiftClient.class); configuration = new DefaultConfigurationBuilder() .withNamespace(namespace) .withNamespaceLazyCreateEnabled(step.isNamespaceLazyCreateEnabled()) .withNamespaceDestroyEnabled(step.isNamespaceDestroyEnabled()) .withMasterUrl(client.getMasterUrl()) .build(); StreamLogger logger = new StreamLogger(listener.getLogger()); LabelProvider labelProvider = new MapLabelProvider(step.getLabels()); namespaceService = isOpenshift ? new OpenshiftNamespaceService.ImmutableOpenshiftNamespaceService(client, configuration, labelProvider, logger) : new DefaultNamespaceService.ImmutableNamespaceService(client, configuration, labelProvider, logger); if (!namespaceService.exists(namespace) && configuration.isNamespaceLazyCreateEnabled()) { namespaceService.create(namespace); } namespaceAction.push(namespace); getContext().newBodyInvoker(). withContext(EnvironmentExpander.merge(getContext().get(EnvironmentExpander.class), new NamespaceExpander(namespace))). withCallback(new NamespaceDestructionCallback(namespace, configuration, namespaceService, namespaceAction)). start(); return false; }