private void patchKubernetesEntity(RequestContext context, Operation inspectResponse, CompletionHandler handler) { String jsonResponse = inspectResponse.getBody(String.class); BaseKubernetesState newState = null; try { newState = context.kubernetesState.getClass().newInstance(); newState.setKubernetesEntityFromJson(jsonResponse); } catch (Throwable ex) { fail(context.request, ex); } sendRequest(Operation.createPatch(this, context.kubernetesState.documentSelfLink) .setBody(newState) .setCompletion(handler)); } }
public static KubernetesDescription createKubernetesEntityDescription( BaseKubernetesState state) { KubernetesDescription entityDescription = new KubernetesDescription(); entityDescription.documentSelfLink = state.descriptionLink; entityDescription.documentDescription = state.documentDescription; entityDescription.tenantLinks = state.tenantLinks; entityDescription.name = state.name; entityDescription.id = state.id; entityDescription.type = state.getType(); entityDescription.customProperties = state.customProperties; return entityDescription; }
.getKubernetesEntities()) { callbackResponse.idToEntityData .put(entity.id, createEntityData(entity.getEntityAsBaseKubernetesObject(), entity.getType()));
break; state.documentSelfLink = state.getMetadata().uid; state.compositeComponentLink = component.documentSelfLink; state.descriptionLink = description.documentSelfLink; state.parentLink = context.kubernetesContext.host.documentSelfLink; state.id = state.getMetadata().uid; state.kubernetesSelfLink = state.getMetadata().selfLink; state.tenantLinks = component.tenantLinks;
private BaseKubernetesState makeEntity(String id, String name, String type, String compositeId) { BaseKubernetesState result = KubernetesUtil.createKubernetesEntityState(type); if (result == null) { return null; } result.id = id; result.name = name; result.parentLink = COMPUTE_HOST_LINK; ObjectMeta metadata = new ObjectMeta(); metadata.name = name; metadata.selfLink = "test"; metadata.namespace = "test"; metadata.uid = id; BaseKubernetesObject object = new BaseKubernetesObject(); object.metadata = metadata; object.kind = type; if (compositeId != null) { object.metadata.labels = new HashMap<>(); object.metadata.labels.put(KubernetesUtil.KUBERNETES_LABEL_APP_ID, compositeId); } result.setKubernetesEntityFromJson(Utils.toJson(object)); return result; }
private void createDiscoveredEntity(AtomicInteger counter, BaseKubernetesState entity, Runnable callback) { logFine("Creating KubernetesState for discovered entity: %s", entity.id); String type = KubernetesUtil.getResourceType(entity.getType()).getName(); AtomicBoolean hasError = new AtomicBoolean(false); sendRequest(OperationUtil .createForcedPost(this, CompositeComponentRegistry.stateFactoryLinkByType(type)) .setBody(entity) .setCompletion( (o, ex) -> { if (ex != null) { logSevere("Failed to create KubernetesState for discovered entity" + " (id=%s): %s", entity.id, ex.getMessage()); if (hasError.compareAndSet(false, true)) { callback.run(); } } else { logInfo("Created KubernetesState for discovered entity: %s", entity.id); } if (counter.decrementAndGet() == 0) { callback.run(); } })); }