@Deprecated @Override public Entity getEntity(String id) { return getEntityManager().getEntity(id); }
@Override public Entity getEntity(String id) { return getEntityManager().getEntity(id); }
@SuppressWarnings("unchecked") protected synchronized T find() { if (entity != null) return entity; if (referrer == null) throw new IllegalStateException("EntityReference "+id+" should have been initialised with a reference parent"); entity = (T) ((EntityInternal)referrer).getManagementContext().getEntityManager().getEntity(id); return entity; }
@SuppressWarnings("unchecked") protected synchronized Collection<T> find() { if (entities!=null) return entities.values(); if (referrer == null) throw new IllegalStateException("EntityReference should have been initialised with a reference parent"); Map<String,T> result = new LinkedHashMap<String,T>(); for (String it : entityRefs) { Entity e = ((EntityInternal)referrer).getManagementContext().getEntityManager().getEntity(it); if (e==null) { LOG.warn("unable to find {}, referred to by {}", it, referrer); } else { result.put(e.getId(), (T)e); } } entities = result; return entities.values(); } }
@Override public Entity getEntity(String id) { if (isInitialManagementContextReal()) { return initialManagementContext.getEntityManager().getEntity(id); } else { return null; } }
/** looks for the given application instance, first by ID then by name * * @throws 404 if not found */ public Application getApplication(String application) { Entity e = mgmt.getEntityManager().getEntity(application); if (e!=null && e instanceof Application) return (Application)e; for (Application app: mgmt.getApplications()) { if (app.getId().equals(application)) return app; if (application.equalsIgnoreCase(app.getDisplayName())) return app; } throw notFound("Application '%s' not found", application); }
/** looks for the given application instance, first by ID then by name * * @throws 404 if not found */ public Application getApplication(String application) { Entity e = mgmt.getEntityManager().getEntity(application); if (e!=null && e instanceof Application) return (Application)e; for (Application app: mgmt.getApplications()) { if (app.getId().equals(application)) return app; if (application.equalsIgnoreCase(app.getDisplayName())) return app; } throw notFound("Application '%s' not found", application); }
@Override public String replaceMember(String memberId) { Entity member = getEntityManager().getEntity(memberId); LOG.info("In {}, replacing member {} ({})", new Object[] {this, memberId, member});
public JsonNode fetch(String items) { Map<String,JsonNode> resultM = MutableMap.<String, JsonNode>of(); for (Application application : mgmt().getApplications()) resultM.put(application.getId(), fromEntity(application)); if (items!=null) { String[] itemsO = items.split(","); for (String item: itemsO) { Entity itemE = mgmt().getEntityManager().getEntity( item.trim() ); while (itemE != null && itemE.getParent()!=null) { resultM.put(itemE.getId(), fromEntity(itemE)); itemE= itemE.getParent(); } } } ArrayNode result = mapper.createArrayNode(); for (JsonNode n: resultM.values()) result.add(n); return result; }
@Override public void removeRegion(String id) { Entity entity = getManagementContext().getEntityManager().getEntity(id); Preconditions.checkNotNull(entity, "No entity found for %s", id); Preconditions.checkArgument(this.equals(entity.getParent()), "Wrong parent (%s) for %s", entity.getParent(), entity); Collection<Location> childLocations = entity.getLocations(); if (entity instanceof Startable) { try { Entities.invokeEffector(this, entity, Startable.STOP).get(); } catch (Exception e) { Exceptions.propagateIfFatal(e); log.warn("Error stopping "+entity+" ("+e+"); proceeding to remove it anyway"); log.debug("Error stopping "+entity+" ("+e+"); proceeding to remove it anyway", e); } } removeChild(entity); removeLocations(childLocations); }
/** finds the entity indicated by the given ID or name * <p> * prefers ID based lookup in which case appId is optional, and if supplied will be enforced. * optionally the name can be supplied, for cases when paths should work across versions, * in which case names will be searched recursively (and the application is required). * * @throws 404 or 412 (unless input is null in which case output is null) */ public EntityLocal getEntity(String application, String entity) { if (entity==null) return null; Application app = application!=null ? getApplication(application) : null; EntityLocal e = (EntityLocal) mgmt.getEntityManager().getEntity(entity); if (e!=null) { if (app==null || app.equals(findTopLevelApplication(e))) return e; throw WebResourceUtils.preconditionFailed("Application '%s' specified does not match application '%s' to which entity '%s' (%s) is associated", application, e.getApplication().getId(), entity, e); } if (application==null) throw WebResourceUtils.notFound("Cannot find entity '%s': no known ID and application not supplied for searching", entity); assert app!=null : "null app should not be returned from getApplication"; e = searchForEntityNamed(app, entity); if (e!=null) return e; throw WebResourceUtils.notFound("Cannot find entity '%s' in application '%s' (%s)", entity, application, app); }
/** finds the entity indicated by the given ID or name * <p> * prefers ID based lookup in which case appId is optional, and if supplied will be enforced. * optionally the name can be supplied, for cases when paths should work across versions, * in which case names will be searched recursively (and the application is required). * * @throws 404 or 412 (unless input is null in which case output is null) */ public EntityLocal getEntity(String application, String entity) { if (entity==null) return null; Application app = application!=null ? getApplication(application) : null; EntityLocal e = (EntityLocal) mgmt.getEntityManager().getEntity(entity); if (e!=null) { if (app==null || app.equals(findTopLevelApplication(e))) return e; throw WebResourceUtils.preconditionFailed("Application '%s' specified does not match application '%s' to which entity '%s' (%s) is associated", application, e.getApplication().getId(), entity, e); } if (application==null) throw WebResourceUtils.notFound("Cannot find entity '%s': no known ID and application not supplied for searching", entity); assert app!=null : "null app should not be returned from getApplication"; e = searchForEntityNamed(app, entity); if (e!=null) return e; throw WebResourceUtils.notFound("Cannot find entity '%s' in application '%s' (%s)", entity, application, app); }