Java Code Examples for org.apache.brooklyn.api.entity.Entity#getApplicationId()

The following examples show how to use org.apache.brooklyn.api.entity.Entity#getApplicationId() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ApplicationResource.java    From brooklyn-server with Apache License 2.0 4 votes vote down vote up
/** depth 0 means no detail even at root; negative means infinite; positive means include details for that many levels 
 * (ie 1 means this entity but no details of descendants) */
private EntitySummary fromEntity(Entity entity, boolean includeTags, int detailDepth, List<String> extraSensorGlobs, List<String> extraConfigGlobs) {
    if (detailDepth==0) {
        return new EntitySummary(
            entity.getId(), 
            entity.getDisplayName(),
            entity.getEntityType().getName(),
            entity.getCatalogItemId(),
            MutableMap.of("self", EntityTransformer.entityUri(entity, ui.getBaseUriBuilder())) );
    }

    Boolean serviceUp = entity.getAttribute(Attributes.SERVICE_UP);

    Lifecycle serviceState = entity.getAttribute(Attributes.SERVICE_STATE_ACTUAL);

    String iconUrl = RegisteredTypes.getIconUrl(entity);
    if (iconUrl!=null) {
        if (brooklyn().isUrlServerSideAndSafe(iconUrl))
            // route to server if it is a server-side url
            iconUrl = EntityTransformer.entityUri(entity, ui.getBaseUriBuilder())+"/icon";
    }

    List<EntitySummary> children = Lists.newArrayList();
    if (!entity.getChildren().isEmpty()) {
        for (Entity child : entity.getChildren()) {
            if (Entitlements.isEntitled(mgmt().getEntitlementManager(), Entitlements.SEE_ENTITY, child)) {
                children.add(fromEntity(child, includeTags, detailDepth-1, extraSensorGlobs, extraConfigGlobs));
            }
        }
    }

    String parentId = null;
    if (entity.getParent()!= null) {
        parentId = entity.getParent().getId();
    }

    List<String> groupIds = Lists.newArrayList();
    if (!entity.groups().isEmpty()) {
        groupIds.addAll(entitiesIdAsArray(entity.groups()));
    }

    List<Map<String, String>> members = Lists.newArrayList();
    if (entity instanceof Group) {
        // use attribute instead of method in case it is read-only
        Collection<Entity> memberEntities = entity.getAttribute(AbstractGroup.GROUP_MEMBERS);
        if (memberEntities != null && !memberEntities.isEmpty())
            members.addAll(entitiesIdAndNameAsList(memberEntities));
    }

    EntityDetail result = new EntityDetail(
            entity.getApplicationId(),
            entity.getId(),
            parentId,
            entity.getDisplayName(),
            entity.getEntityType().getName(),
            serviceUp,
            serviceState,
            iconUrl,
            entity.getCatalogItemId(),
            children,
            groupIds,
            members,
            MutableMap.of("self", EntityTransformer.entityUri(entity, ui.getBaseUriBuilder())) );
    
    if (includeTags) {
        result.setExtraField("tags", resolving(MutableList.copyOf(entity.tags().getTags())).preferJson(true).resolve() );
    }
    result.setExtraField("creationTimeUtc", entity.getCreationTime());
    addSensorsByGlobs(result, entity, extraSensorGlobs);
    addConfigByGlobs(result, entity, extraConfigGlobs);
    
    return result;
}
 
Example 2
Source File: LocalUsageManager.java    From brooklyn-server with Apache License 2.0 4 votes vote down vote up
protected void recordLocationEvent(final Location loc, final Entity caller, final Lifecycle state) {
    log.debug("Storing location lifecycle usage event: location {} in state {}; caller context {}", new Object[] {loc, state, caller});
    ConcurrentMap<String, LocationUsage> eventMap = managementContext.getStorage().<String, LocationUsage>getMap(LOCATION_USAGE_KEY);
    
    String entityTypeName = caller.getEntityType().getName();
    String appId = caller.getApplicationId();

    final LocationUsage.LocationEvent event = new LocationUsage.LocationEvent(state, caller.getId(), entityTypeName, appId, getUser());
    
    
    // Don't call out to alien-code (i.e. loc.toMetadataRecord()) while holding mutex. It might take a while,
    // e.g. ssh'ing to the machine!
    // If we don't have a usage record, then generate one outside of the mutex. But then double-check while
    // holding the mutex to see if another thread has created one. If it has, stick with that rather than 
    // overwriting it.
    LocationUsage usage;
    synchronized (mutex) {
        usage = eventMap.get(loc.getId());
    }
    if (usage == null) {
        usage = new LocationUsage(loc.getId(), ((LocationInternal)loc).toMetadataRecord());
    }
    
    synchronized (mutex) {
        LocationUsage otherUsage = eventMap.get(loc.getId());
        if (otherUsage != null) {
            usage = otherUsage;
        }
        usage.addEvent(event);
        eventMap.put(loc.getId(), usage);
        
        execOnListeners(new Function<UsageListener, Void>() {
                @Override
                public Void apply(UsageListener listener) {
                    listener.onLocationEvent(new LocationMetadataImpl(loc), event);
                    return null;
                }
                @Override
                public String toString() {
                    return "locationEvent("+loc+", "+state+")";
                }});
    }
}