Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JENKINS-38370] Start defining APIs that are for the master JVM only #2556

Merged
merged 1 commit into from
Oct 24, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion core/src/main/java/hudson/ExtensionList.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import java.util.logging.Logger;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import jenkins.util.io.OnMaster;

/**
* Retains the known extension instances for the given type 'T'.
Expand All @@ -68,7 +69,7 @@
* @see jenkins.model.Jenkins#getExtensionList(Class)
* @see jenkins.model.Jenkins#getDescriptorList(Class)
*/
public class ExtensionList<T> extends AbstractList<T> {
public class ExtensionList<T> extends AbstractList<T> implements OnMaster {
/**
* @deprecated as of 1.417
* Use {@link #jenkins}
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/hudson/ExtensionPoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.lang.annotation.Retention;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Target;
import jenkins.util.io.OnMaster;

/**
* Marker interface that designates extensible components
Expand All @@ -47,7 +48,7 @@
* @see Plugin
* @see Extension
*/
public interface ExtensionPoint {
public interface ExtensionPoint extends OnMaster {
/**
* Used by designers of extension points (direct subtypes of {@link ExtensionPoint}) to indicate that
* the legacy instances are scoped to {@link Jenkins} instance. By default, legacy instances are
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/hudson/model/Descriptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import jenkins.model.GlobalConfiguration;
import jenkins.model.GlobalConfigurationCategory;
import jenkins.model.Jenkins;
import jenkins.util.io.OnMaster;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.kohsuke.stapler.*;
Expand Down Expand Up @@ -125,7 +126,7 @@
* @author Kohsuke Kawaguchi
* @see Describable
*/
public abstract class Descriptor<T extends Describable<T>> implements Saveable {
public abstract class Descriptor<T extends Describable<T>> implements Saveable, OnMaster {
/**
* The class being described by this descriptor.
*/
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/hudson/model/Item.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import hudson.Functions;
import jenkins.util.SystemProperties;
import hudson.security.PermissionScope;
import jenkins.util.io.OnMaster;
import org.kohsuke.stapler.StaplerRequest;

import java.io.IOException;
Expand Down Expand Up @@ -67,7 +68,7 @@
* @see Items
* @see ItemVisitor
*/
public interface Item extends PersistenceRoot, SearchableModelObject, AccessControlled {
public interface Item extends PersistenceRoot, SearchableModelObject, AccessControlled, OnMaster {
/**
* Gets the parent that contains this item.
*/
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/hudson/model/Job.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
* @author Kohsuke Kawaguchi
*/
public abstract class Job<JobT extends Job<JobT, RunT>, RunT extends Run<JobT, RunT>>
extends AbstractItem implements ExtensionPoint, StaplerOverridable, ModelObjectWithChildren, OnMaster {
extends AbstractItem implements ExtensionPoint, StaplerOverridable, ModelObjectWithChildren {

private static final Logger LOGGER = Logger.getLogger(Job.class.getName());

Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/jenkins/model/Jenkins.java
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@
import jenkins.util.JenkinsJVM;
import jenkins.util.Timer;
import jenkins.util.io.FileBoolean;
import jenkins.util.io.OnMaster;
import jenkins.util.xml.XMLUtils;
import net.jcip.annotations.GuardedBy;
import net.sf.json.JSONObject;
Expand Down Expand Up @@ -323,7 +324,7 @@
@ExportedBean
public class Jenkins extends AbstractCIBase implements DirectlyModifiableTopLevelItemGroup, StaplerProxy, StaplerFallback,
ModifiableViewGroup, AccessControlled, DescriptorByNameOwner,
ModelObjectWithContextMenu, ModelObjectWithChildren {
ModelObjectWithContextMenu, ModelObjectWithChildren, OnMaster {
Copy link
Member

@daniel-beck daniel-beck Oct 11, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Node implements it already.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, it never hurts to make explicit for a better Javadoc visiblity

private transient final Queue queue;

/**
Expand Down
32 changes: 32 additions & 0 deletions core/src/main/java/jenkins/util/io/OnMaster.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,36 @@
* @since 1.475
*/
public interface OnMaster {
// TODO uncomment once we can have a delegating ClassFilter, also add SystemProperty to toggle feature
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As noted in an earlier revision:

if (blacklist.contains(name)) {
    return true;
}
delegate.check(name);
return false;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be great to have references to the issue in this TODO

// @Extension
// @Restricted(NoExternalUse.class)
// class ChannelConfiguratorImpl extends ChannelConfigurator {
// @Override
// public void onChannelBuilding(ChannelBuilder builder, @Nullable Object context) {
// if (context instanceof SlaveComputer) {
// builder.withClassFilter(new ClassFilterImpl(builder.getClassFilter(), OnMaster.class.getName, ...));
// }
// }
// }
//
// @Restricted(NoExternalUse.class)
// class ClassFilterImpl extends ClassFilter {
// private final ClassFilter delegate;
// private final Set<String> blacklist;
//
// public ClassFilterImpl(ClassFilter delegate, String... blacklist) {
// this.blacklist = new HashSet<>(blacklist);
// this.delegate = delegate;
// }
//
// @Override
// protected boolean isBlacklisted(String name) {
// return blacklist.contains(name) || delegate.isBlacklisted(name);
// }
//
// @Override
// protected boolean isBlacklisted(Class c) {
// return c.getAnnotation(MasterJVMOnly.class) != null || delegate.isBlacklisted(c);
// }
// }
}