use of com.ibm.streamsx.topology.context.Placeable in project streamsx.topology by IBMStreams.
the class PlacementInfo method colocate.
/**
* Fuse a number of placeables.
* If fusing occurs then the fusing id
* is set as explicitColocate in the placement JSON object in
* the operator's config.
* @throws IllegalArgumentException if Placeables are from different
* topologies or if Placeable.isPlaceable()==false.
*/
static boolean colocate(Placeable<?> first, Placeable<?>... toFuse) {
Set<Placeable<?>> elements = new HashSet<>();
elements.add(first);
elements.addAll(Arrays.asList(toFuse));
// check high level constraints
for (Placeable<?> element : elements) {
if (!element.isPlaceable())
throw new IllegalArgumentException(Messages.getString("CORE_ILLEGAL_OPERATION_PLACEABLE"));
if (!first.topology().equals(element.topology()))
throw new IllegalArgumentException(Messages.getString("CORE_DIFFERENT_TOPOLOGIES", first.topology().getName(), element.topology().getName()));
}
if (elements.size() < 2)
return false;
disallowColocateInLowLatency(elements);
disallowColocateIsolatedOpWithParent(first, toFuse);
final JsonPrimitive colocateTag = new JsonPrimitive("__spl_colocate$" + nextFuseId.getAndIncrement());
Set<String> fusedResourceTags = new HashSet<>();
for (Placeable<?> element : elements) {
JsonObject placement = placement(element);
JsonArray colocateIds = arrayCreate(placement, PLACEMENT_COLOCATE_TAGS);
colocateIds.add(colocateTag);
// Determine the union of all resource tags for the colocated operators
if (placement.has(PLACEMENT_RESOURCE_TAGS)) {
addToSet(fusedResourceTags, array(placement, PLACEMENT_RESOURCE_TAGS));
}
}
JsonArray fusedResourceTagsJson = setToArray(fusedResourceTags);
// And finally update all the JSON info
for (Placeable<?> element : elements) {
JsonObject placement = placement(element);
placement.add(PLACEMENT_RESOURCE_TAGS, fusedResourceTagsJson);
}
return true;
}
Aggregations