brooklyn.entity.basic.Entities.isManaged()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(9.4k)|赞(0)|评价(0)|浏览(100)

本文整理了Java中brooklyn.entity.basic.Entities.isManaged()方法的一些代码示例,展示了Entities.isManaged()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Entities.isManaged()方法的具体详情如下:
包路径:brooklyn.entity.basic.Entities
类名称:Entities
方法名:isManaged

Entities.isManaged介绍

暂无

代码示例

代码示例来源:origin: io.brooklyn/brooklyn-core

@Override
  public boolean apply(@Nullable Entity input) {
    return input != null && Entities.isManaged(input);
  }
};

代码示例来源:origin: io.brooklyn/brooklyn-launcher

/** 
 * Specifies that the launcher should manage the given Brooklyn application.
 * The application must not yet be managed. 
 * The application will not be started as part of this call (callers can
 * subsequently call {@link start()} or {@link getApplications()}.
 * 
 * @see application(ApplicationBuilder)
 */
public BrooklynLauncher application(Application app) {
  if (Entities.isManaged(app)) throw new IllegalArgumentException("Application must not already be managed");
  appsToManage.add(checkNotNull(app, "app"));
  return this;
}

代码示例来源:origin: io.brooklyn/brooklyn-core

/**
 * Starts managing the given (unmanaged) app, using the given management context.
 *
 * @see #startManagement(Entity)
 */
public static ManagementContext startManagement(Application app, ManagementContext mgmt) {
  if (isManaged(app)) {
    throw new IllegalStateException("Application "+app+" is already managed, so can't set brooklyn properties");
  }
  mgmt.getEntityManager().manage(app);
  return mgmt;
}

代码示例来源:origin: io.brooklyn/brooklyn-software-nosql

public boolean isViableSeed(Entity member) {
  // TODO would be good to reuse the better logic in ServiceFailureDetector
  // (e.g. if that didn't just emit a notification but set a sensor as well?)
  boolean managed = Entities.isManaged(member);
  String hostname = member.getAttribute(Attributes.HOSTNAME);
  boolean serviceUp = Boolean.TRUE.equals(member.getAttribute(Attributes.SERVICE_UP));
  Lifecycle serviceState = member.getAttribute(Attributes.SERVICE_STATE);
  boolean hasFailed = !managed || (serviceState == Lifecycle.ON_FIRE) || (serviceState == Lifecycle.RUNNING && !serviceUp) || (serviceState == Lifecycle.STOPPED);
  boolean result = (hostname != null && !hasFailed);
  if (log.isTraceEnabled()) log.trace("Node {} in Cluster {}: viableSeed={}; hostname={}; serviceUp={}; serviceState={}; hasFailed={}", new Object[] {member, this, result, hostname, serviceUp, serviceState, hasFailed});
  return result;
}
public boolean isRunningSeed(Entity member) {

代码示例来源:origin: io.brooklyn/brooklyn-software-nosql

public boolean isViableSeed(Entity member) {
    // TODO remove duplication from CassandraClusterImpl.SeedTracker.isViableSeed
    boolean managed = Entities.isManaged(member);
    String hostname = member.getAttribute(Attributes.HOSTNAME);
    boolean serviceUp = Boolean.TRUE.equals(member.getAttribute(Attributes.SERVICE_UP));
    Lifecycle serviceState = member.getAttribute(Attributes.SERVICE_STATE);
    boolean hasFailed = !managed || (serviceState == Lifecycle.ON_FIRE) || (serviceState == Lifecycle.RUNNING && !serviceUp) || (serviceState == Lifecycle.STOPPED);
    boolean result = (hostname != null && !hasFailed);
    if (log.isTraceEnabled()) log.trace("Node {} in Cluster {}: viableSeed={}; hostname={}; serviceUp={}; serviceState={}; hasFailed={}", new Object[] {member, this, result, hostname, serviceUp, serviceState, hasFailed});
    return result;
  }
};

代码示例来源:origin: io.brooklyn/brooklyn-core

/**
 * Starts managing the given (unmanaged) app, setting the given brooklyn properties on the new
 * management context.
 *
 * @see #startManagement(Entity)
 */
public static ManagementContext startManagement(Application app, BrooklynProperties props) {
  if (isManaged(app)) {
    throw new IllegalStateException("Application "+app+" is already managed, so can't set brooklyn properties");
  }
  ManagementContext mgmt = new LocalManagementContext(props);
  mgmt.getEntityManager().manage(app);
  return mgmt;
}

代码示例来源:origin: io.brooklyn/brooklyn-core

/** stops, destroys, and unmanages the given entity -- does as many as are valid given the type and state */
public static void destroy(Entity e) {
  if (isManaged(e)) {
    if (e instanceof Startable) Entities.invokeEffector((EntityLocal)e, e, Startable.STOP).getUnchecked();
    if (e instanceof EntityInternal) ((EntityInternal)e).destroy();
    unmanage(e);
    log.debug("destroyed and unmanaged "+e+"; mgmt now "+
        (e.getApplicationId()==null ? "(no app)" : e.getApplication().getManagementContext())+" - managed? "+isManaged(e));
  } else {
    log.debug("skipping destroy of "+e+": not managed");
  }
}

代码示例来源:origin: io.brooklyn/brooklyn-core

/** brings this entity under management iff its ancestor is managed, returns true in that case;
 * otherwise returns false in the expectation that the ancestor will become managed,
 * or throws exception if it has no parent or a non-application root
 * (will throw if e is an Application; see also {@link #startManagement(Entity)} ) */
public static boolean manage(Entity e) {
  Entity o = e.getParent();
  Entity eum = e; //highest unmanaged ancestor
  if (o==null) throw new IllegalStateException("Can't manage "+e+" because it is an orphan");
  while (o.getParent()!=null) {
    if (!isManaged(o)) eum = o;
    o = o.getParent();
  }
  if (isManaged(o)) {
    ((EntityInternal)o).getManagementContext().getEntityManager().manage(eum);
    return true;
  }
  if (!(o instanceof Application))
    throw new IllegalStateException("Can't manage "+e+" because it is not rooted at an application");
  return false;
}

代码示例来源:origin: io.brooklyn/brooklyn-core

/** convenience for starting an entity, esp a new Startable instance which has been created dynamically
 * (after the application is started) */
public static void start(Entity e, Collection<? extends Location> locations) {
  if (!isManaged(e) && !manage(e)) {
    log.warn("Using discouraged mechanism to start management -- Entities.start(Application, Locations) -- caller should create and use the preferred management context");
    startManagement(e);
  }
  if (e instanceof Startable) Entities.invokeEffector((EntityLocal)e, e, Startable.START,
      MutableMap.of("locations", locations)).getUnchecked();
}

代码示例来源:origin: io.brooklyn/brooklyn-core

/** stops, destroys, and unmanages all apps in the given context,
 * and then terminates the management context */
public static void destroyAll(ManagementContext mgmt) {
  Exception error = null;
  if (mgmt instanceof NonDeploymentManagementContext) {
    // log here because it is easy for tests to destroyAll(app.getMgmtContext())
    // which will *not* destroy the mgmt context if the app has been stopped!
    log.warn("Entities.destroyAll invoked on non-deployment "+mgmt+" - not likely to have much effect! " +
        "(This usually means the mgmt context has been taken from entity has been destroyed. " +
        "To destroy other things on the management context ensure you keep a handle to the context " +
        "before the entity is destroyed, such as by creating the management context first.)");
  }
  if (!mgmt.isRunning()) return;
  log.debug("destroying all apps in "+mgmt+": "+mgmt.getApplications());
  for (Application app: mgmt.getApplications()) {
    log.debug("destroying app "+app+" (managed? "+isManaged(app)+"; mgmt is "+mgmt+")");
    try {
      destroy(app);
      log.debug("destroyed app "+app+"; mgmt now "+mgmt);
    } catch (Exception e) {
      log.warn("problems destroying app "+app+" (mgmt now "+mgmt+", will rethrow at least one exception): "+e);
      if (error==null) error = e;
    }
  }
  if (mgmt instanceof ManagementContextInternal) 
    ((ManagementContextInternal)mgmt).terminate();
  if (error!=null) throw Exceptions.propagate(error);
}

代码示例来源:origin: io.brooklyn/brooklyn-core

/**
 * stops, destroys, and unmanages the given application -- and terminates the mangaement context;
 * does as many as are valid given the type and state
 * @deprecated since 0.6.0 use destroy(Application) if you DONT want to destroy the mgmt context,
 * or destroy(app.getManagementContext()) if you want to destory everything in the app's mgmt context
 */
@Deprecated
public static void destroyAll(Application app) {
  if (isManaged(app)) {
    ManagementContext managementContext = app.getManagementContext();
    if (app instanceof Startable) Entities.invokeEffector((EntityLocal)app, app, Startable.STOP).getUnchecked();
    if (app instanceof AbstractEntity) ((AbstractEntity)app).destroy();
    unmanage(app);
    if (managementContext instanceof ManagementContextInternal) ((ManagementContextInternal)managementContext).terminate();
  }
}

代码示例来源:origin: io.brooklyn/brooklyn-core

/** brings this entity under management, creating a local management context if necessary
 * (assuming root is an application).
 * returns existing management context if there is one (non-deployment),
 * or new local mgmt context if not,
 * or throwing exception if root is not an application
 * <p>
 * callers are recommended to use {@link #manage(Entity)} instead unless they know
 * a plain-vanilla non-root management context is sufficient (e.g. in tests)
 * <p>
 * this method may change, but is provided as a stop-gap to prevent ad-hoc things
 * being done in the code which are even more likely to break! */
public static ManagementContext startManagement(Entity e) {
  Entity o = e;
  Entity eum = e; //highest unmanaged ancestor
  while (o.getParent()!=null) {
    if (!isManaged(o)) eum = o;
    o = o.getParent();
  }
  if (isManaged(o)) {
    ManagementContext mgmt = ((EntityInternal)o).getManagementContext();
    mgmt.getEntityManager().manage(eum);
    return mgmt;
  }
  if (!(o instanceof Application))
    throw new IllegalStateException("Can't manage "+e+" because it is not rooted at an application");
  ManagementContext mgmt = new LocalManagementContext();
  mgmt.getEntityManager().manage(o);
  return mgmt;
}

代码示例来源:origin: io.brooklyn/brooklyn-software-messaging

if (Entities.isManaged(this)) Entities.manage(zookeeper);
  setAttribute(ZOOKEEPER, zookeeper);
if (Entities.isManaged(this)) Entities.manage(cluster);
setAttribute(CLUSTER, cluster);

代码示例来源:origin: io.brooklyn/brooklyn-software-webapp

if (Entities.isManaged(this)) Entities.manage(cluster);
setAttribute(CLUSTER, cluster);
  if (Entities.isManaged(this)) Entities.manage(controller);
  setAttribute(CONTROLLER, controller);

相关文章