Search in sources :

Example 16 with Type

use of org.bf2.operator.resources.v1alpha1.ManagedKafkaCondition.Type in project kas-fleetshard by bf2fc6cc711aee1a0c2a.

the class FleetShardOperatorManager method createEndpoint.

public static String createEndpoint(KubeClient kubeClient) {
    String externalEndpointName = SYNC_NAME + "-external";
    if (kubeClient.isGenericKubernetes()) {
        if (kubeClient.client().services().inNamespace(OPERATOR_NS).list().getItems().stream().anyMatch(service -> service.getMetadata().getName().equals(externalEndpointName))) {
            kubeClient.client().services().inNamespace(OPERATOR_NS).withName(externalEndpointName).delete();
        }
        kubeClient.cmdClient().namespace(OPERATOR_NS).execInCurrentNamespace("expose", "service", SYNC_NAME, "--type=LoadBalancer", "--name", externalEndpointName);
        return new ExecBuilder().withCommand("minikube", "service", "--url", externalEndpointName, "-n", OPERATOR_NS).logToOutput(false).exec().out().trim();
    } else {
        OpenShiftClient openShiftClient = kubeClient.client().adapt(OpenShiftClient.class);
        if (openShiftClient.routes().inNamespace(OPERATOR_NS).list().getItems().stream().anyMatch(service -> service.getMetadata().getName().equals(externalEndpointName))) {
            openShiftClient.routes().inNamespace(OPERATOR_NS).withName(externalEndpointName).delete();
        }
        kubeClient.cmdClient().namespace(OPERATOR_NS).execInCurrentNamespace("expose", "service", SYNC_NAME, "--name", externalEndpointName);
        Route r = openShiftClient.routes().inNamespace(OPERATOR_NS).withName(externalEndpointName).get();
        return String.format("%s://%s:%d", r.getSpec().getPort().getTargetPort().getStrVal(), r.getSpec().getHost(), r.getSpec().getPort().getTargetPort().getStrVal().equals("http") ? 80 : 443);
    }
}
Also used : OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) ExecBuilder(org.bf2.test.executor.ExecBuilder) Route(io.fabric8.openshift.api.model.Route)

Example 17 with Type

use of org.bf2.operator.resources.v1alpha1.ManagedKafkaCondition.Type in project kas-fleetshard by bf2fc6cc711aee1a0c2a.

the class ManagedKafkaDeployment method start.

public void start() {
    ManagedKafkaResourceType type = new ManagedKafkaResourceType();
    Resource<ManagedKafka> resource = type.resource(cluster.kubeClient(), managedKafka);
    Predicate<ManagedKafka> readyCheck = type.readiness(cluster.kubeClient());
    readyFuture = TestUtils.asyncWaitFor("cluster ready", 1000, 600_000, () -> readyCheck.test(resource.get()));
}
Also used : ManagedKafka(org.bf2.operator.resources.v1alpha1.ManagedKafka) ManagedKafkaResourceType(org.bf2.systemtest.framework.resource.ManagedKafkaResourceType)

Example 18 with Type

use of org.bf2.operator.resources.v1alpha1.ManagedKafkaCondition.Type in project srs-fleet-manager by bf2fc6cc711aee1a0c2a.

the class UsageMetrics method init.

public synchronized void init() {
    expirationPeriod = Duration.ofSeconds(expirationPeriodSeconds);
    int stagger = 0;
    // Only stagger if the expiration period is at least 1 minute (testing support).
    if (expirationPeriod.compareTo(Duration.ofMinutes(1)) >= 0) {
        stagger = new Random().nextInt(expirationPeriodSeconds) + 1;
        log.debug("Staggering usage metrics cache expiration by {} seconds", stagger);
    }
    nextExpiration = Instant.now().plus(Duration.ofSeconds(stagger));
    for (RegistryStatusValueDto status : RegistryStatusValueDto.values()) {
        Gauge.builder(USAGE_STATISTICS_REGISTRIES_STATUS, () -> {
            Arc.initialize();
            var ctx = Arc.container().requestContext();
            ctx.activate();
            try {
                return getUsageStatisticsCached().getRegistryCountPerStatus().get(status);
            } finally {
                ctx.deactivate();
            }
        }).tags(Tags.of(TAG_USAGE_STATISTICS_STATUS, status.value())).register(metrics);
    }
    for (RegistryInstanceTypeValueDto type : RegistryInstanceTypeValueDto.values()) {
        Gauge.builder(USAGE_STATISTICS_REGISTRIES_TYPE, () -> {
            Arc.initialize();
            var ctx = Arc.container().requestContext();
            ctx.activate();
            try {
                return getUsageStatisticsCached().getRegistryCountPerType().get(type);
            } finally {
                ctx.deactivate();
            }
        }).tags(Tags.of(TAG_USAGE_STATISTICS_TYPE, type.value())).register(metrics);
    }
    Gauge.builder(USAGE_STATISTICS_ACTIVE_USERS, () -> {
        Arc.initialize();
        var ctx = Arc.container().requestContext();
        ctx.activate();
        try {
            return getUsageStatisticsCached().getActiveUserCount();
        } finally {
            ctx.deactivate();
        }
    }).register(metrics);
    Gauge.builder(USAGE_STATISTICS_ACTIVE_ORGANISATIONS, () -> {
        Arc.initialize();
        var ctx = Arc.container().requestContext();
        ctx.activate();
        try {
            return getUsageStatisticsCached().getActiveOrganisationCount();
        } finally {
            ctx.deactivate();
        }
    }).register(metrics);
}
Also used : RegistryStatusValueDto(org.bf2.srs.fleetmanager.rest.service.model.RegistryStatusValueDto) Random(java.util.Random) RegistryInstanceTypeValueDto(org.bf2.srs.fleetmanager.rest.service.model.RegistryInstanceTypeValueDto)

Example 19 with Type

use of org.bf2.operator.resources.v1alpha1.ManagedKafkaCondition.Type in project srs-fleet-manager by bf2fc6cc711aee1a0c2a.

the class RegistryServiceImpl method createRegistry.

@Audited
@Override
public RegistryDto createRegistry(RegistryCreateDto registryCreate) throws RegistryStorageConflictException, TermsRequiredException, ResourceLimitReachedException, EvalInstancesNotAllowedException, TooManyEvalInstancesForUserException, TooManyInstancesException, AccountManagementServiceException {
    final AccountInfo accountInfo = authService.extractAccountInfo();
    // Make sure we have more instances available (max capacity not yet reached).
    long instanceCount = storage.getRegistryCountTotal();
    if (instanceCount >= maxInstances) {
        throw new TooManyInstancesException();
    }
    // Figure out if we are going to create a standard or eval instance.
    ResourceType resourceType = evalInstancesOnlyEnabled ? ResourceType.REGISTRY_INSTANCE_EVAL : accountManagementService.determineAllowedResourceType(accountInfo);
    if (resourceType == ResourceType.REGISTRY_INSTANCE_EVAL) {
        // Are eval instances allowed?
        if (!evalInstancesEnabled) {
            throw new EvalInstancesNotAllowedException();
        }
        // Limit the # of eval instances per user.  Need to check storage for list of eval registry instances.
        List<RegistryData> registriesByOwner = storage.getRegistriesByOwner(accountInfo.getAccountUsername());
        int evalInstanceCount = 0;
        for (RegistryData registryData : registriesByOwner) {
            // TODO Perform a dedicated query
            if (RegistryInstanceTypeValueDto.EVAL.value().equals(registryData.getInstanceType())) {
                evalInstanceCount++;
            }
        }
        if (evalInstanceCount >= maxEvalInstancesPerUser) {
            throw new TooManyEvalInstancesForUserException();
        }
    }
    // Try to consume some quota from AMS for the appropriate resource type (standard or eval).  If successful
    // we'll get back a subscriptionId - if not we'll throw an exception.
    String subscriptionId = accountManagementService.createResource(accountInfo, resourceType);
    // Convert to registry data and persist it in the DB.
    RegistryInstanceTypeValueDto instanceType = resourceTypeToInstanceType(resourceType);
    RegistryData registryData = convertRegistry.convert(registryCreate, subscriptionId, accountInfo.getAccountUsername(), accountInfo.getOrganizationId(), accountInfo.getAccountId(), instanceType);
    // Generate the ID
    registryData.setId(UUID.randomUUID().toString());
    storage.createOrUpdateRegistry(registryData);
    tasks.submit(ScheduleRegistryTask.builder().registryId(registryData.getId()).build());
    return convertRegistry.convert(registryData);
}
Also used : TooManyInstancesException(org.bf2.srs.fleetmanager.spi.common.TooManyInstancesException) EvalInstancesNotAllowedException(org.bf2.srs.fleetmanager.spi.common.EvalInstancesNotAllowedException) ResourceType(org.bf2.srs.fleetmanager.spi.common.model.ResourceType) TooManyEvalInstancesForUserException(org.bf2.srs.fleetmanager.spi.common.TooManyEvalInstancesForUserException) RegistryData(org.bf2.srs.fleetmanager.storage.sqlPanacheImpl.model.RegistryData) RegistryInstanceTypeValueDto(org.bf2.srs.fleetmanager.rest.service.model.RegistryInstanceTypeValueDto) AccountInfo(org.bf2.srs.fleetmanager.spi.common.model.AccountInfo) Audited(org.bf2.srs.fleetmanager.common.operation.auditing.Audited)

Example 20 with Type

use of org.bf2.operator.resources.v1alpha1.ManagedKafkaCondition.Type 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;
}
Also used : DeploymentSpec(org.bf2.cos.fleetshard.api.DeploymentSpec) ConnectorDeploymentStatusOperators(org.bf2.cos.fleet.manager.model.ConnectorDeploymentStatusOperators) MetaV1Condition(org.bf2.cos.fleet.manager.model.MetaV1Condition) ConnectorDeploymentStatus(org.bf2.cos.fleet.manager.model.ConnectorDeploymentStatus)

Aggregations

ManagedConnector (org.bf2.cos.fleetshard.api.ManagedConnector)5 Secret (io.fabric8.kubernetes.api.model.Secret)4 Objects (java.util.Objects)4 Collectors (java.util.stream.Collectors)4 Operator (org.bf2.cos.fleetshard.api.Operator)4 ObjectMetaBuilder (io.fabric8.kubernetes.api.model.ObjectMetaBuilder)3 QuarkusTest (io.quarkus.test.junit.QuarkusTest)3 List (java.util.List)3 Map (java.util.Map)3 ApplicationScoped (javax.enterprise.context.ApplicationScoped)3 ConnectorDeploymentStatus (org.bf2.cos.fleet.manager.model.ConnectorDeploymentStatus)3 MetaV1Condition (org.bf2.cos.fleet.manager.model.MetaV1Condition)3 Resources (org.bf2.cos.fleetshard.support.resources.Resources)3 Test (org.junit.jupiter.api.Test)3 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 Condition (io.fabric8.kubernetes.api.model.Condition)2 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)2 ObjectMeta (io.fabric8.kubernetes.api.model.ObjectMeta)2 SecretBuilder (io.fabric8.kubernetes.api.model.SecretBuilder)2