use of org.bf2.cos.fleetshard.api.Operator in project srs-fleet-manager by bf2fc6cc711aee1a0c2a.
the class AccountManagementSystemRestClientTest method getQuotaCostList.
@Test
public void getQuotaCostList() {
final QuotaCostList quotaCostList = accountManagementSystemRestClient.getQuotaCostList("1pcZDw72EPhdanw4pJEnrudOnyj", true);
Assertions.assertNotNull(quotaCostList);
Assertions.assertEquals(20, quotaCostList.getTotal());
Assertions.assertNotNull(quotaCostList.getItems());
Assertions.assertFalse(quotaCostList.getItems().isEmpty());
Assertions.assertEquals(20, quotaCostList.getItems().size());
Assertions.assertEquals("add-on|addon-cluster-logging-operator", quotaCostList.getItems().get(0).getQuota_id());
}
use of org.bf2.cos.fleetshard.api.Operator in project cos-fleetshard by bf2fc6cc711aee1a0c2a.
the class ConnectorStatusExtractor method extract.
public static ConnectorDeploymentStatus extract(ManagedConnector connector) {
ConnectorDeploymentStatus status = new ConnectorDeploymentStatus();
DeploymentSpec deployment = connector.getSpec().getDeployment();
if (connector.getStatus() != null && connector.getStatus().getPhase() != null) {
deployment = connector.getStatus().getDeployment();
}
status.setResourceVersion(deployment.getDeploymentResourceVersion());
if (connector.getSpec().getOperatorSelector() == null || connector.getSpec().getOperatorSelector().getId() == null) {
status.setPhase(STATE_FAILED);
status.addConditionsItem(new MetaV1Condition().type(Conditions.TYPE_READY).status(Conditions.STATUS_FALSE).message("No assignable operator").reason(Conditions.NO_ASSIGNABLE_OPERATOR_REASON).lastTransitionTime(Conditions.now()));
return status;
}
if (connector.getStatus() != null && connector.getStatus().getConnectorStatus() != null) {
status.setOperators(new ConnectorDeploymentStatusOperators().assigned(toConnectorOperator(connector.getStatus().getConnectorStatus().getAssignedOperator())).available(toConnectorOperator(connector.getStatus().getConnectorStatus().getAvailableOperator())));
if (connector.getStatus().getConnectorStatus() != null) {
if (connector.getStatus().getConnectorStatus().getPhase() != null) {
status.setPhase(connector.getStatus().getConnectorStatus().getPhase());
}
if (connector.getStatus().getConnectorStatus().getConditions() != null) {
for (var cond : connector.getStatus().getConnectorStatus().getConditions()) {
status.addConditionsItem(toMetaV1Condition(cond));
}
}
}
}
if (status.getPhase() == null) {
if (DESIRED_STATE_DELETED.equals(deployment.getDesiredState())) {
status.setPhase(STATE_DE_PROVISIONING);
} else if (DESIRED_STATE_STOPPED.equals(deployment.getDesiredState())) {
status.setPhase(STATE_DE_PROVISIONING);
} else {
status.setPhase(STATE_PROVISIONING);
}
}
return status;
}
use of org.bf2.cos.fleetshard.api.Operator in project cos-fleetshard by bf2fc6cc711aee1a0c2a.
the class ConnectorDeploymentProvisioner method createManagedConnector.
private ManagedConnector createManagedConnector(String uow, ConnectorDeployment deployment, HasMetadata owner) {
ManagedConnector connector = fleetShard.getConnector(deployment).orElseGet(() -> {
LOGGER.info("Connector not found (cluster_id: {}, connector_id: {}, deployment_id: {}, resource_version: {}), creating a new one", fleetShard.getClusterId(), deployment.getSpec().getConnectorId(), deployment.getId(), deployment.getMetadata().getResourceVersion());
return Connectors.newConnector(fleetShard.getClusterId(), deployment.getSpec().getConnectorId(), deployment.getId(), Map.of());
});
// TODO: change APIs to include a single operator
// move operator one level up
// include full operator info in ConnectorDeployment APIs
ArrayNode operatorsMeta = deployment.getSpec().getShardMetadata().withArray("operators");
if (operatorsMeta.size() != 1) {
throw new IllegalArgumentException("Multiple selectors are not yet supported");
}
OperatorSelector operatorSelector = new OperatorSelector(deployment.getSpec().getOperatorId(), operatorsMeta.get(0).requiredAt("/type").asText(), operatorsMeta.get(0).requiredAt("/version").asText());
if (operatorSelector.getId() == null) {
final OperatorSelector currentSelector = connector.getSpec().getOperatorSelector();
// don't select a new operator if previously set.
if (currentSelector != null && currentSelector.getId() != null) {
operatorSelector.setId(currentSelector.getId());
} else {
OperatorSelectorUtil.assign(operatorSelector, fleetShard.lookupOperators()).map(Operator::getId).ifPresent(operatorSelector::setId);
}
}
if (operatorSelector.getId() != null) {
Resources.setLabel(connector, Resources.LABEL_OPERATOR_ASSIGNED, operatorSelector.getId());
}
if (operatorSelector.getType() != null) {
Resources.setLabel(connector, Resources.LABEL_OPERATOR_TYPE, operatorSelector.getType());
}
if (config != null) {
config.connectors().labels().forEach((k, v) -> {
Resources.setLabel(connector, k, v);
});
config.connectors().annotations().forEach((k, v) -> {
Resources.setAnnotation(connector, k, v);
});
}
connector.getMetadata().setOwnerReferences(List.of(new OwnerReferenceBuilder().withApiVersion(owner.getApiVersion()).withKind(owner.getKind()).withName(owner.getMetadata().getName()).withUid(owner.getMetadata().getUid()).withBlockOwnerDeletion(true).build()));
// add resource version to label
Resources.setLabel(connector, Resources.LABEL_DEPLOYMENT_RESOURCE_VERSION, "" + deployment.getMetadata().getResourceVersion());
// add uow
Resources.setLabel(connector, Resources.LABEL_UOW, uow);
connector.getSpec().getDeployment().setDeploymentResourceVersion(deployment.getMetadata().getResourceVersion());
connector.getSpec().getDeployment().setDesiredState(deployment.getSpec().getDesiredState());
connector.getSpec().getDeployment().setConnectorTypeId(deployment.getSpec().getConnectorTypeId());
connector.getSpec().getDeployment().setConnectorResourceVersion(deployment.getSpec().getConnectorResourceVersion());
KafkaConnectionSettings kafkaConnectionSettings = deployment.getSpec().getKafka();
if (kafkaConnectionSettings != null) {
connector.getSpec().getDeployment().setKafka(new KafkaSpecBuilder().withId(kafkaConnectionSettings.getId()).withUrl(kafkaConnectionSettings.getUrl()).build());
}
SchemaRegistryConnectionSettings schemaRegistryConnectionSettings = deployment.getSpec().getSchemaRegistry();
if (schemaRegistryConnectionSettings != null) {
connector.getSpec().getDeployment().setSchemaRegistry(new SchemaRegistrySpecBuilder().withId(schemaRegistryConnectionSettings.getId()).withUrl(schemaRegistryConnectionSettings.getUrl()).build());
}
connector.getSpec().getDeployment().setConnectorResourceVersion(deployment.getSpec().getConnectorResourceVersion());
connector.getSpec().getDeployment().setSecret(Secrets.generateConnectorSecretId(deployment.getId()));
connector.getSpec().getDeployment().setUnitOfWork(uow);
connector.getSpec().setOperatorSelector(operatorSelector);
LOGGER.info("Provisioning connector id={} rv={} - {}/{}: {}", connector.getMetadata().getName(), connector.getSpec().getDeployment().getDeploymentResourceVersion(), fleetShard.getConnectorsNamespace(), connector.getSpec().getConnectorId(), Serialization.asJson(connector.getSpec()));
try {
return fleetShard.createConnector(connector);
} catch (Exception e) {
LOGGER.warn("", e);
throw e;
}
}
Aggregations