Search in sources :

Example 1 with BridgeError

use of com.redhat.service.smartevents.infra.exceptions.BridgeError in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class BridgeErrorServiceTest method checkExceptionIsNotInCatalog.

private void checkExceptionIsNotInCatalog(Class<?> clazz) {
    BridgeError bridgeError = service.getError(clazz).get();
    assertThat(bridgeError).withFailMessage(String.format("exception %s not found in the errors", clazz)).isNotNull();
    assertThat(service.getUserError(bridgeError.getId())).withFailMessage(String.format("exception %s should not be in the user errors", clazz)).isEmpty();
}
Also used : BridgeError(com.redhat.service.smartevents.infra.exceptions.BridgeError)

Example 2 with BridgeError

use of com.redhat.service.smartevents.infra.exceptions.BridgeError in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class ExternalUserExceptionMapper method toResponse.

@Override
public Response toResponse(ExternalUserException e) {
    LOGGER.debug("Failure", e);
    Optional<BridgeError> error = bridgeErrorService.getError(e);
    ResponseBuilder builder = Response.status(e.getStatusCode());
    if (error.isPresent()) {
        ErrorResponse errorResponse = ErrorResponse.from(error.get());
        errorResponse.setReason(e.getMessage());
        builder.entity(errorResponse);
    } else {
        LOGGER.warn("Information for exception type {} cannot be found", e.getClass());
        builder.entity(e.getMessage());
    }
    return builder.build();
}
Also used : BridgeError(com.redhat.service.smartevents.infra.exceptions.BridgeError) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) ErrorResponse(com.redhat.service.smartevents.infra.api.models.responses.ErrorResponse)

Example 3 with BridgeError

use of com.redhat.service.smartevents.infra.exceptions.BridgeError in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class BridgeExecutorController method reconcile.

@Override
public UpdateControl<BridgeExecutor> reconcile(BridgeExecutor bridgeExecutor, Context context) {
    LOGGER.debug("Create or update BridgeProcessor: '{}' in namespace '{}'", bridgeExecutor.getMetadata().getName(), bridgeExecutor.getMetadata().getNamespace());
    Secret secret = bridgeExecutorService.fetchBridgeExecutorSecret(bridgeExecutor);
    if (secret == null) {
        LOGGER.debug("Secrets for the BridgeProcessor '{}' have been not created yet.", bridgeExecutor.getMetadata().getName());
        return UpdateControl.noUpdate();
    }
    // Check if the image of the executor has to be updated
    String image = bridgeExecutorService.getExecutorImage();
    if (!image.equals(bridgeExecutor.getSpec().getImage())) {
        bridgeExecutor.getSpec().setImage(image);
        return UpdateControl.updateResource(bridgeExecutor);
    }
    Deployment deployment = bridgeExecutorService.fetchOrCreateBridgeExecutorDeployment(bridgeExecutor, secret);
    if (!Readiness.isDeploymentReady(deployment)) {
        LOGGER.debug("Executor deployment BridgeProcessor: '{}' in namespace '{}' is NOT ready", bridgeExecutor.getMetadata().getName(), bridgeExecutor.getMetadata().getNamespace());
        bridgeExecutor.getStatus().setConditionsFromDeployment(deployment);
        if (DeploymentStatusUtils.isTimeoutFailure(deployment)) {
            notifyDeploymentFailure(bridgeExecutor, DeploymentStatusUtils.getReasonAndMessageForTimeoutFailure(deployment));
        } else if (DeploymentStatusUtils.isStatusReplicaFailure(deployment)) {
            notifyDeploymentFailure(bridgeExecutor, DeploymentStatusUtils.getReasonAndMessageForReplicaFailure(deployment));
        }
        return UpdateControl.updateStatus(bridgeExecutor);
    }
    LOGGER.debug("Executor deployment BridgeProcessor: '{}' in namespace '{}' is ready", bridgeExecutor.getMetadata().getName(), bridgeExecutor.getMetadata().getNamespace());
    // Create Service
    Service service = bridgeExecutorService.fetchOrCreateBridgeExecutorService(bridgeExecutor, deployment);
    if (service.getStatus() == null) {
        LOGGER.debug("Executor service BridgeProcessor: '{}' in namespace '{}' is NOT ready", bridgeExecutor.getMetadata().getName(), bridgeExecutor.getMetadata().getNamespace());
        bridgeExecutor.getStatus().markConditionFalse(ConditionType.Ready);
        bridgeExecutor.getStatus().markConditionTrue(ConditionType.Augmentation, ConditionReason.ServiceNotReady);
        return UpdateControl.updateStatus(bridgeExecutor);
    }
    Optional<ServiceMonitor> serviceMonitor = monitorService.fetchOrCreateServiceMonitor(bridgeExecutor, service, BridgeExecutor.COMPONENT_NAME);
    if (serviceMonitor.isPresent()) {
        // this is an optional resource
        LOGGER.debug("Executor service monitor resource BridgeExecutor: '{}' in namespace '{}' is ready", bridgeExecutor.getMetadata().getName(), bridgeExecutor.getMetadata().getNamespace());
    } else {
        LOGGER.warn("Executor service monitor resource BridgeExecutor: '{}' in namespace '{}' is failed to deploy, Prometheus not installed.", bridgeExecutor.getMetadata().getName(), bridgeExecutor.getMetadata().getNamespace());
        BridgeError prometheusNotAvailableError = bridgeErrorService.getError(PrometheusNotInstalledException.class).orElseThrow(() -> new RuntimeException("PrometheusNotInstalledException not found in error catalog"));
        bridgeExecutor.getStatus().markConditionFalse(ConditionType.Ready, ConditionReason.PrometheusUnavailable, prometheusNotAvailableError.getReason(), prometheusNotAvailableError.getCode());
        notifyManager(bridgeExecutor, ManagedResourceStatus.FAILED);
        return UpdateControl.updateStatus(bridgeExecutor);
    }
    LOGGER.debug("Executor service BridgeProcessor: '{}' in namespace '{}' is ready", bridgeExecutor.getMetadata().getName(), bridgeExecutor.getMetadata().getNamespace());
    if (!bridgeExecutor.getStatus().isReady()) {
        bridgeExecutor.getStatus().markConditionTrue(ConditionType.Ready);
        bridgeExecutor.getStatus().markConditionFalse(ConditionType.Augmentation);
        notifyManager(bridgeExecutor, ManagedResourceStatus.READY);
        return UpdateControl.updateStatus(bridgeExecutor);
    }
    return UpdateControl.noUpdate();
}
Also used : Secret(io.fabric8.kubernetes.api.model.Secret) BridgeError(com.redhat.service.smartevents.infra.exceptions.BridgeError) ServiceMonitor(io.fabric8.openshift.api.model.monitoring.v1.ServiceMonitor) PrometheusNotInstalledException(com.redhat.service.smartevents.infra.exceptions.definitions.platform.PrometheusNotInstalledException) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) BridgeErrorService(com.redhat.service.smartevents.infra.exceptions.BridgeErrorService) ServiceMonitorService(com.redhat.service.smartevents.shard.operator.monitoring.ServiceMonitorService) Service(io.fabric8.kubernetes.api.model.Service) BridgeExecutorService(com.redhat.service.smartevents.shard.operator.BridgeExecutorService)

Example 4 with BridgeError

use of com.redhat.service.smartevents.infra.exceptions.BridgeError in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class BridgeErrorServiceTest method checkExceptionIsInCatalog.

private void checkExceptionIsInCatalog(Class<?> clazz) {
    BridgeError bridgeError = service.getError(clazz).get();
    assertThat(bridgeError).withFailMessage(String.format("exception %s not found in the errors", clazz)).isNotNull();
    assertThat(service.getUserError(bridgeError.getId())).withFailMessage(String.format("exception %s not found in the user errors", clazz)).isNotEmpty();
}
Also used : BridgeError(com.redhat.service.smartevents.infra.exceptions.BridgeError)

Example 5 with BridgeError

use of com.redhat.service.smartevents.infra.exceptions.BridgeError in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class BridgeIngressController method reconcile.

@Override
public UpdateControl<BridgeIngress> reconcile(BridgeIngress bridgeIngress, Context context) {
    LOGGER.debug("Create or update BridgeIngress: '{}' in namespace '{}'", bridgeIngress.getMetadata().getName(), bridgeIngress.getMetadata().getNamespace());
    Secret secret = bridgeIngressService.fetchBridgeIngressSecret(bridgeIngress);
    if (secret == null) {
        LOGGER.debug("Secrets for the BridgeIngress '{}' have been not created yet.", bridgeIngress.getMetadata().getName());
        return UpdateControl.noUpdate();
    }
    // Check if the image of the ingress has to be updated
    String image = bridgeIngressService.getIngressImage();
    if (!image.equals(bridgeIngress.getSpec().getImage())) {
        bridgeIngress.getSpec().setImage(image);
        return UpdateControl.updateResource(bridgeIngress);
    }
    Deployment deployment = bridgeIngressService.fetchOrCreateBridgeIngressDeployment(bridgeIngress, secret);
    if (!Readiness.isDeploymentReady(deployment)) {
        LOGGER.debug("Ingress deployment BridgeIngress: '{}' in namespace '{}' is NOT ready", bridgeIngress.getMetadata().getName(), bridgeIngress.getMetadata().getNamespace());
        bridgeIngress.getStatus().setConditionsFromDeployment(deployment);
        if (DeploymentStatusUtils.isTimeoutFailure(deployment)) {
            notifyDeploymentFailure(bridgeIngress, DeploymentStatusUtils.getReasonAndMessageForTimeoutFailure(deployment));
        } else if (DeploymentStatusUtils.isStatusReplicaFailure(deployment)) {
            notifyDeploymentFailure(bridgeIngress, DeploymentStatusUtils.getReasonAndMessageForReplicaFailure(deployment));
        }
        return UpdateControl.updateStatus(bridgeIngress);
    }
    LOGGER.debug("Ingress deployment BridgeIngress: '{}' in namespace '{}' is ready", bridgeIngress.getMetadata().getName(), bridgeIngress.getMetadata().getNamespace());
    // Create Service
    Service service = bridgeIngressService.fetchOrCreateBridgeIngressService(bridgeIngress, deployment);
    if (service.getStatus() == null) {
        LOGGER.debug("Ingress service BridgeIngress: '{}' in namespace '{}' is NOT ready", bridgeIngress.getMetadata().getName(), bridgeIngress.getMetadata().getNamespace());
        bridgeIngress.getStatus().markConditionFalse(ConditionType.Ready);
        bridgeIngress.getStatus().markConditionTrue(ConditionType.Augmentation, ConditionReason.ServiceNotReady);
        return UpdateControl.updateStatus(bridgeIngress);
    }
    LOGGER.debug("Ingress service BridgeIngress: '{}' in namespace '{}' is ready", bridgeIngress.getMetadata().getName(), bridgeIngress.getMetadata().getNamespace());
    // Create Route
    NetworkResource networkResource = networkingService.fetchOrCreateNetworkIngress(bridgeIngress, service);
    if (!networkResource.isReady()) {
        LOGGER.debug("Ingress networking resource BridgeIngress: '{}' in namespace '{}' is NOT ready", bridgeIngress.getMetadata().getName(), bridgeIngress.getMetadata().getNamespace());
        bridgeIngress.getStatus().markConditionFalse(ConditionType.Ready);
        bridgeIngress.getStatus().markConditionTrue(ConditionType.Augmentation, ConditionReason.NetworkResourceNotReady);
        return UpdateControl.updateStatus(bridgeIngress);
    }
    LOGGER.debug("Ingress networking resource BridgeIngress: '{}' in namespace '{}' is ready", bridgeIngress.getMetadata().getName(), bridgeIngress.getMetadata().getNamespace());
    Optional<ServiceMonitor> serviceMonitor = monitorService.fetchOrCreateServiceMonitor(bridgeIngress, service, BridgeIngress.COMPONENT_NAME);
    if (serviceMonitor.isPresent()) {
        // this is an optional resource
        LOGGER.debug("Ingress monitor resource BridgeIngress: '{}' in namespace '{}' is ready", bridgeIngress.getMetadata().getName(), bridgeIngress.getMetadata().getNamespace());
    } else {
        LOGGER.warn("Ingress monitor resource BridgeIngress: '{}' in namespace '{}' is failed to deploy, Prometheus not installed.", bridgeIngress.getMetadata().getName(), bridgeIngress.getMetadata().getNamespace());
        BridgeError prometheusNotAvailableError = bridgeErrorService.getError(PrometheusNotInstalledException.class).orElseThrow(() -> new RuntimeException("PrometheusNotInstalledException not found in error catalog"));
        bridgeIngress.getStatus().markConditionFalse(ConditionType.Ready, ConditionReason.PrometheusUnavailable, prometheusNotAvailableError.getReason(), prometheusNotAvailableError.getCode());
        notifyManager(bridgeIngress, ManagedResourceStatus.FAILED);
        return UpdateControl.updateStatus(bridgeIngress);
    }
    if (!bridgeIngress.getStatus().isReady() || !networkResource.getEndpoint().equals(bridgeIngress.getStatus().getEndpoint())) {
        bridgeIngress.getStatus().setEndpoint(networkResource.getEndpoint());
        bridgeIngress.getStatus().markConditionTrue(ConditionType.Ready);
        bridgeIngress.getStatus().markConditionFalse(ConditionType.Augmentation);
        notifyManager(bridgeIngress, ManagedResourceStatus.READY);
        return UpdateControl.updateStatus(bridgeIngress);
    }
    return UpdateControl.noUpdate();
}
Also used : Secret(io.fabric8.kubernetes.api.model.Secret) NetworkResource(com.redhat.service.smartevents.shard.operator.networking.NetworkResource) BridgeError(com.redhat.service.smartevents.infra.exceptions.BridgeError) ServiceMonitor(io.fabric8.openshift.api.model.monitoring.v1.ServiceMonitor) PrometheusNotInstalledException(com.redhat.service.smartevents.infra.exceptions.definitions.platform.PrometheusNotInstalledException) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) NetworkingService(com.redhat.service.smartevents.shard.operator.networking.NetworkingService) BridgeErrorService(com.redhat.service.smartevents.infra.exceptions.BridgeErrorService) ServiceMonitorService(com.redhat.service.smartevents.shard.operator.monitoring.ServiceMonitorService) Service(io.fabric8.kubernetes.api.model.Service) BridgeIngressService(com.redhat.service.smartevents.shard.operator.BridgeIngressService)

Aggregations

BridgeError (com.redhat.service.smartevents.infra.exceptions.BridgeError)5 BridgeErrorService (com.redhat.service.smartevents.infra.exceptions.BridgeErrorService)2 PrometheusNotInstalledException (com.redhat.service.smartevents.infra.exceptions.definitions.platform.PrometheusNotInstalledException)2 ServiceMonitorService (com.redhat.service.smartevents.shard.operator.monitoring.ServiceMonitorService)2 Secret (io.fabric8.kubernetes.api.model.Secret)2 Service (io.fabric8.kubernetes.api.model.Service)2 Deployment (io.fabric8.kubernetes.api.model.apps.Deployment)2 ServiceMonitor (io.fabric8.openshift.api.model.monitoring.v1.ServiceMonitor)2 ErrorResponse (com.redhat.service.smartevents.infra.api.models.responses.ErrorResponse)1 BridgeExecutorService (com.redhat.service.smartevents.shard.operator.BridgeExecutorService)1 BridgeIngressService (com.redhat.service.smartevents.shard.operator.BridgeIngressService)1 NetworkResource (com.redhat.service.smartevents.shard.operator.networking.NetworkResource)1 NetworkingService (com.redhat.service.smartevents.shard.operator.networking.NetworkingService)1 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)1