/** * Gets the specified property or null if the property is not configured for this Node. * * @param clazz the type of the property * * @return null if the property is not configured * * @since 2.37 */ @CheckForNull public <T extends NodeProperty> T getNodeProperty(Class<T> clazz) { for (NodeProperty p: getNodeProperties()) { if (clazz.isInstance(p)) { return clazz.cast(p); } } return null; }
/** * Gets the property from the given classname or null if the property * is not configured for this Node. * * @param className The classname of the property * * @return null if the property is not configured * * @since 2.37 */ @CheckForNull public NodeProperty getNodeProperty(String className) { for (NodeProperty p: getNodeProperties()) { if (p.getClass().getName().equals(className)) { return p; } } return null; }
@Override public Object onConvert(Type targetType, Class targetTypeErasure, Object jsonSource) { if (jsonForProperties != jsonSource) { return old.get().onConvert(targetType, targetTypeErasure, jsonSource); } try { DescribableList<NodeProperty<?>, NodePropertyDescriptor> tmp = new DescribableList<NodeProperty<?>, NodePropertyDescriptor>(Saveable.NOOP,getNodeProperties().toList()); tmp.rebuild(req, jsonForProperties, NodeProperty.all()); return tmp.toList(); } catch (FormException e) { throw new IllegalArgumentException(e); } catch (IOException e) { throw new IllegalArgumentException(e); } } }));
ToolLocationNodeProperty property = node.getNodeProperties().get(ToolLocationNodeProperty.class); if (property != null) { result = property.getHome(installation);
/** * Creates an environment variable override to be used for launching processes on this node. * * @see ProcStarter#envs(Map) * @since 1.489 */ public @Nonnull EnvVars buildEnvironment(@Nonnull TaskListener listener) throws IOException, InterruptedException { EnvVars env = new EnvVars(); Node node = getNode(); if (node==null) return env; // bail out for (NodeProperty nodeProperty: Jenkins.getInstance().getGlobalNodeProperties()) { nodeProperty.buildEnvVars(env,listener); } for (NodeProperty nodeProperty: node.getNodeProperties()) { nodeProperty.buildEnvVars(env,listener); } // TODO: hmm, they don't really belong String rootUrl = Jenkins.getInstance().getRootUrl(); if(rootUrl!=null) { env.put("HUDSON_URL", rootUrl); // Legacy. env.put("JENKINS_URL", rootUrl); } return env; }
for (NodeProperty prop: getNodeProperties()) { CauseOfBlockage c = prop.canTake(item); if (c!=null) return c;
/** * Gets the specified property or null if the property is not configured for this Node. * * @param clazz the type of the property * * @return null if the property is not configured * * @since 2.37 */ @CheckForNull public <T extends NodeProperty> T getNodeProperty(Class<T> clazz) { for (NodeProperty p: getNodeProperties()) { if (clazz.isInstance(p)) { return clazz.cast(p); } } return null; }
private EnvVars getEnvVars(Node n) { return getEnvVars(n.getNodeProperties()); }
/** * Gets the property from the given classname or null if the property * is not configured for this Node. * * @param className The classname of the property * * @return null if the property is not configured * * @since 2.37 */ @CheckForNull public NodeProperty getNodeProperty(String className) { for (NodeProperty p: getNodeProperties()) { if (p.getClass().getName().equals(className)) { return p; } } return null; }
private EnvVars getEnvVars(Node n) { return getEnvVars(n.getNodeProperties()); }
private List<String> lookForJavaHome(Node node) { List<String> ret = new ArrayList<>(); if(node != null && node.getNodeProperties() != null){ for (NodeProperty property : node.getNodeProperties()){ if(property instanceof EnvironmentVariablesNodeProperty){ EnvVars env = ((EnvironmentVariablesNodeProperty) property).getEnvVars(); if (env != null && env.containsKey(JAVA_HOME)) { ret.add(env.get(JAVA_HOME) + BIN_JAVA); } } } } return ret; }
/** * Finds the {@link NodeProperty} for the external workspace definition. * * @param node the current node * @return the node property for the external workspace manager * @throws IOException if node property was not found */ @Nonnull private static ExternalWorkspaceProperty findNodeProperty(Node node) throws IOException { DescribableList<NodeProperty<?>, NodePropertyDescriptor> nodeProperties = node.getNodeProperties(); ExternalWorkspaceProperty exwsNodeProperty = null; for (NodeProperty<?> nodeProperty : nodeProperties) { if (nodeProperty instanceof ExternalWorkspaceProperty) { exwsNodeProperty = (ExternalWorkspaceProperty) nodeProperty; break; } } if (exwsNodeProperty == null) { String message = format("There is no External Workspace config defined in Node '%s' config", node.getDisplayName()); throw new AbortException(message); } return exwsNodeProperty; }
private List<String> lookForTools(Node node) { List<String> ret = new ArrayList<>(); Descriptor jdk = Jenkins.getInstance().getDescriptorByType(JDK.DescriptorImpl.class); if(node != null && node.getNodeProperties() != null){ for (NodeProperty property : node.getNodeProperties()){ if (property instanceof ToolLocationNodeProperty) { for (ToolLocation tool : ((ToolLocationNodeProperty) property).getLocations()) { if (tool.getType() == jdk) { ret.add(tool.getHome() + BIN_JAVA); } } } } } return ret; } }
@Override public Object onConvert(Type targetType, Class targetTypeErasure, Object jsonSource) { if (jsonForProperties != jsonSource) { return old.get().onConvert(targetType, targetTypeErasure, jsonSource); } try { DescribableList<NodeProperty<?>, NodePropertyDescriptor> tmp = new DescribableList<NodeProperty<?>, NodePropertyDescriptor>(Saveable.NOOP,getNodeProperties().toList()); tmp.rebuild(req, jsonForProperties, NodeProperty.all()); return tmp.toList(); } catch (FormException e) { throw new IllegalArgumentException(e); } catch (IOException e) { throw new IllegalArgumentException(e); } } }));
/** * Checks if the location of the tool is overridden for the given node, and if so, * return the node-specific home directory. Otherwise return {@code installation.getHome()} * * <p> * This is the core logic behind {@link NodeSpecific#forNode(Node)} for {@link ToolInstallation}. * * @return * never null. * @deprecated since 2009-04-09. * Use {@link ToolInstallation#translateFor(Node,TaskListener)} */ public static String getToolHome(Node node, ToolInstallation installation, TaskListener log) throws IOException, InterruptedException { String result = null; // node-specific configuration takes precedence ToolLocationNodeProperty property = node.getNodeProperties().get(ToolLocationNodeProperty.class); if (property != null) result = property.getHome(installation); if (result != null) return result; // consult translators for( ToolLocationTranslator t : ToolLocationTranslator.all() ) { result = t.getToolHome(node, installation, log); if(result!=null) return result; } // fall back is no-op return installation.getHome(); }
/** * Checks if the location of the tool is overridden for the given node, and if so, * return the node-specific home directory. Otherwise return {@code installation.getHome()} * * <p> * This is the core logic behind {@link NodeSpecific#forNode(Node)} for {@link ToolInstallation}. * * @return * never null. * @deprecated since 2009-04-09. * Use {@link ToolInstallation#translateFor(Node,TaskListener)} */ public static String getToolHome(Node node, ToolInstallation installation, TaskListener log) throws IOException, InterruptedException { String result = null; // node-specific configuration takes precedence ToolLocationNodeProperty property = node.getNodeProperties().get(ToolLocationNodeProperty.class); if (property != null) result = property.getHome(installation); if (result != null) return result; // consult translators for( ToolLocationTranslator t : ToolLocationTranslator.all() ) { result = t.getToolHome(node, installation, log); if(result!=null) return result; } // fall back is no-op return installation.getHome(); }
/** * Checks if the location of the tool is overridden for the given node, and if so, * return the node-specific home directory. Otherwise return {@code installation.getHome()} * * <p> * This is the core logic behind {@link NodeSpecific#forNode(Node)} for {@link ToolInstallation}. * * @return * never null. * @deprecated since 2009-04-09. * Use {@link ToolInstallation#translateFor(Node,TaskListener)} */ public static String getToolHome(Node node, ToolInstallation installation, TaskListener log) throws IOException, InterruptedException { String result = null; // node-specific configuration takes precedence ToolLocationNodeProperty property = node.getNodeProperties().get(ToolLocationNodeProperty.class); if (property != null) result = property.getHome(installation); if (result != null) return result; // consult translators for( ToolLocationTranslator t : ToolLocationTranslator.all() ) { result = t.getToolHome(node, installation, log); if(result!=null) return result; } // fall back is no-op return installation.getHome(); }
/** * Creates an environment variable override to be used for launching processes on this node. * * @see ProcStarter#envs(Map) * @since 1.489 */ public @Nonnull EnvVars buildEnvironment(@Nonnull TaskListener listener) throws IOException, InterruptedException { EnvVars env = new EnvVars(); Node node = getNode(); if (node==null) return env; // bail out for (NodeProperty nodeProperty: Jenkins.getInstance().getGlobalNodeProperties()) { nodeProperty.buildEnvVars(env,listener); } for (NodeProperty nodeProperty: node.getNodeProperties()) { nodeProperty.buildEnvVars(env,listener); } // TODO: hmm, they don't really belong String rootUrl = Jenkins.getInstance().getRootUrl(); if(rootUrl!=null) { env.put("HUDSON_URL", rootUrl); // Legacy. env.put("JENKINS_URL", rootUrl); } return env; }
public void buildEnvVars(AbstractBuild<?, ?> build, EnvVars env) { for (NodeProperty nodeProperty: Hudson.getInstance().getGlobalNodeProperties()) { if (nodeProperty instanceof EnvironmentVariablesNodeProperty) { env.overrideAll(((EnvironmentVariablesNodeProperty)nodeProperty).getEnvVars()); } } for (NodeProperty nodeProperty: Computer.currentComputer().getNode().getNodeProperties()) { if (nodeProperty instanceof EnvironmentVariablesNodeProperty) { env.overrideAll(((EnvironmentVariablesNodeProperty)nodeProperty).getEnvVars()); } } } }
public CauseOfBlockage canTake(Queue.BuildableItem item) { Label l = item.getAssignedLabel(); if(l!=null && !l.contains(this)) return CauseOfBlockage.fromMessage(Messages._Node_LabelMissing(getNodeName(),l)); // the task needs to be executed on label that this node doesn't have. if(l==null && getMode()== Mode.EXCLUSIVE) return CauseOfBlockage.fromMessage(Messages._Node_BecauseNodeIsReserved(getNodeName())); // this node is reserved for tasks that are tied to it // Check each NodeProperty to see whether they object to this node // taking the task for (NodeProperty prop: getNodeProperties()) { CauseOfBlockage c = prop.canTake(item); if (c!=null) return c; } // Looks like we can take the task return null; }