EntitySpec<?> dockerHostSpec = EntitySpec.create(getConfig(DOCKER_HOST_SPEC))
.configure(DockerHost.DOCKER_INFRASTRUCTURE, this)
.configure(SoftwareProcess.SUGGESTED_VERSION, getConfig(DOCKER_VERSION))
.configure(SoftwareProcess.CHILDREN_STARTABLE_MODE, ChildStartableMode.BACKGROUND_LATE);
DynamicCluster hosts = addChild(EntitySpec.create(DynamicCluster.class)
.configure(Cluster.INITIAL_SIZE, initialSize)
.configure(DynamicCluster.QUARANTINE_FAILED_ENTITIES, true)
.configure(DynamicCluster.MEMBER_SPEC, dockerHostSpec)
.displayName("Docker Hosts"));
DynamicGroup fabric = addChild(EntitySpec.create(DynamicGroup.class)
.configure(DynamicGroup.ENTITY_FILTER, Predicates.and(Predicates.instanceOf(DockerContainer.class), EntityPredicates.attributeEqualTo(DockerContainer.DOCKER_INFRASTRUCTURE, this)))
.configure(DynamicGroup.MEMBER_DELEGATE_CHILDREN, true)
.displayName("All Docker Containers"));
DynamicMultiGroup buckets = addChild(EntitySpec.create(DynamicMultiGroup.class)
.configure(DynamicMultiGroup.ENTITY_FILTER, sameInfrastructure)
.configure(DynamicMultiGroup.RESCAN_INTERVAL, 15L)
.configure(DynamicMultiGroup.BUCKET_FUNCTION, new Function<Entity, String>() {
@Override
public String apply(@Nullable Entity input) {
return input.getApplication().getDisplayName() + ":" + input.getApplicationId();
}
})
.configure(DynamicMultiGroup.BUCKET_SPEC, EntitySpec.create(BasicGroup.class)
.configure(BasicGroup.MEMBER_DELEGATE_CHILDREN, true))
.displayName("Docker Applications"));
if (getConfig(WEAVE_ENABLED)) {
WeaveInfrastructure weave = addChild(EntitySpec.create(WeaveInfrastructure.class)
.configure(WeaveInfrastructure.DOCKER_INFRASTRUCTURE, this));
setAttribute(WEAVE_INFRASTRUCTURE, weave);
if (Entities.isManaged(this)) {
Entities.manage(weave);
}
}
if (Entities.isManaged(this)) {
Entities.manage(hosts);
Entities.manage(fabric);
Entities.manage(buckets);
}
setAttribute(DOCKER_HOST_CLUSTER, hosts);
setAttribute(DOCKER_CONTAINER_FABRIC, fabric);
setAttribute(DOCKER_APPLICATIONS, buckets);
hosts.addEnricher(Enrichers.builder()
.aggregating(DockerHost.CPU_USAGE)
.computingAverage()
.fromMembers()
.publishing(MachineAttributes.AVERAGE_CPU_USAGE)
.valueToReportIfNoSensors(0d)
.build());
hosts.addEnricher(Enrichers.builder()
.aggregating(DOCKER_CONTAINER_COUNT)
.computingSum()
.fromMembers()
.publishing(DOCKER_CONTAINER_COUNT)
.build());