Search in sources :

Example 1 with InfrastructureException

use of org.eclipse.che.api.workspace.server.spi.InfrastructureException in project che-server by eclipse-che.

the class PVCSubPathHelper method execute.

private void execute(RuntimeIdentity identity, String workspaceId, String namespace, String pvcName, String[] commandBase, Map<String, String> startOptions, boolean watchFailureEvents, String... arguments) {
    final String jobName = commandBase[0];
    final String podName = jobName + '-' + workspaceId;
    final String[] command = buildCommand(commandBase, arguments);
    final Pod pod = newPod(podName, pvcName, command);
    securityContextProvisioner.provision(pod.getSpec());
    nodeSelectorProvisioner.provision(pod.getSpec());
    tolerationsProvisioner.provision(pod.getSpec());
    KubernetesDeployments deployments = null;
    try {
        KubernetesNamespace ns = factory.access(workspaceId, namespace);
        if (!checkPVCExistsAndNotTerminating(ns, pvcName)) {
            return;
        }
        deployments = ns.deployments();
        deployments.create(pod);
        watchLogsIfDebugEnabled(deployments, pod, identity, startOptions);
        PodStatus finishedStatus = waitPodStatus(podName, deployments, watchFailureEvents);
        if (POD_PHASE_FAILED.equals(finishedStatus.getPhase())) {
            String logs = deployments.getPodLogs(podName);
            LOG.error("Job command '{}' execution is failed. Logs: {}", Arrays.toString(command), // Force logs onto one line
            Strings.nullToEmpty(logs).replace("\n", " \\n"));
        }
    } catch (InfrastructureException ex) {
        LOG.error("Unable to perform '{}' command for the workspace '{}' cause: '{}'", Arrays.toString(command), workspaceId, ex.getMessage());
        deployments.stopWatch(true);
    } finally {
        if (deployments != null) {
            deployments.stopWatch();
            try {
                deployments.delete(podName);
            } catch (InfrastructureException ignored) {
            }
        }
    }
}
Also used : PodStatus(io.fabric8.kubernetes.api.model.PodStatus) Pod(io.fabric8.kubernetes.api.model.Pod) KubernetesDeployments(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesDeployments) InfrastructureException(org.eclipse.che.api.workspace.server.spi.InfrastructureException) KubernetesNamespace(org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesNamespace)

Example 2 with InfrastructureException

use of org.eclipse.che.api.workspace.server.spi.InfrastructureException in project che-server by eclipse-che.

the class GatewayTlsProvisioner method useSecureProtocolForGatewayConfigMap.

private void useSecureProtocolForGatewayConfigMap(ConfigMap configMap) throws InfrastructureException {
    Map<String, ServerConfigImpl> servers = Annotations.newDeserializer(configMap.getMetadata().getAnnotations()).servers();
    if (servers.isEmpty()) {
        return;
    }
    if (servers.size() != 1) {
        throw new InfrastructureException("Expected exactly 1 server in Gateway configuration ConfigMap '" + configMap.getMetadata().getName() + "'. This is a bug, please report.");
    }
    Entry<String, ServerConfigImpl> serverConfigEntry = servers.entrySet().iterator().next();
    ServerConfigImpl serverConfig = serverConfigEntry.getValue();
    serverConfig.setProtocol(getSecureProtocol(serverConfig.getProtocol()));
    configMap.getMetadata().getAnnotations().putAll(Annotations.newSerializer().server(serverConfigEntry.getKey(), serverConfig).annotations());
}
Also used : ServerConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl) InfrastructureException(org.eclipse.che.api.workspace.server.spi.InfrastructureException)

Example 3 with InfrastructureException

use of org.eclipse.che.api.workspace.server.spi.InfrastructureException in project che-server by eclipse-che.

the class AsyncStorageProvisioner method provision.

public void provision(KubernetesEnvironment k8sEnv, RuntimeIdentity identity) throws InfrastructureException {
    if (!parseBoolean(k8sEnv.getAttributes().get(ASYNC_PERSIST_ATTRIBUTE))) {
        return;
    }
    if (!COMMON_STRATEGY.equals(pvcStrategy)) {
        String message = format("Workspace configuration not valid: Asynchronous storage available only for 'common' PVC strategy, but got %s", pvcStrategy);
        LOG.warn(message);
        k8sEnv.addWarning(new WarningImpl(4200, message));
        throw new InfrastructureException(message);
    }
    if (!isEphemeral(k8sEnv.getAttributes())) {
        String message = format("Workspace configuration not valid: Asynchronous storage available only if '%s' attribute set to false", PERSIST_VOLUMES_ATTRIBUTE);
        LOG.warn(message);
        k8sEnv.addWarning(new WarningImpl(4200, message));
        throw new InfrastructureException(message);
    }
    String namespace = identity.getInfrastructureNamespace();
    String userId = identity.getOwnerId();
    KubernetesClient k8sClient = kubernetesClientFactory.create(identity.getWorkspaceId());
    String configMapName = namespace + ASYNC_STORAGE_CONFIG;
    createPvcIfNotExist(k8sClient, namespace, userId);
    createConfigMapIfNotExist(k8sClient, namespace, configMapName, userId, k8sEnv);
    createAsyncStoragePodIfNotExist(k8sClient, namespace, configMapName, userId);
    createStorageServiceIfNotExist(k8sClient, namespace, userId);
}
Also used : KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) WarningImpl(org.eclipse.che.api.workspace.server.model.impl.WarningImpl) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) InfrastructureException(org.eclipse.che.api.workspace.server.spi.InfrastructureException)

Example 4 with InfrastructureException

use of org.eclipse.che.api.workspace.server.spi.InfrastructureException in project che-server by eclipse-che.

the class GitCredentialStorageFileSecretApplier method applySecret.

@Override
public void applySecret(KubernetesEnvironment env, RuntimeIdentity runtimeIdentity, Secret secret) throws InfrastructureException {
    super.applySecret(env, runtimeIdentity, secret);
    final String secretMountPath = secret.getMetadata().getAnnotations().get(ANNOTATION_MOUNT_PATH);
    Set<String> keys = secret.getData().keySet();
    if (keys.size() != 1) {
        throw new InfrastructureException(format("Invalid git credential secret data. It should contain only 1 data item but it have %d", keys.size()));
    }
    Path gitSecretFilePath = Paths.get(secretMountPath, keys.iterator().next());
    ConfigMap gitConfigMap = env.getConfigMaps().get(GitConfigProvisioner.GIT_CONFIG_MAP_NAME);
    if (gitConfigMap != null) {
        Map<String, String> gitConfigMapData = gitConfigMap.getData();
        String gitConfig = gitConfigMapData.get(GitConfigProvisioner.GIT_CONFIG);
        if (gitConfig != null) {
            if (gitConfig.contains("helper = store --file") && gitConfig.contains("[credential]")) {
                throw new InfrastructureException(format("Multiple git credential secrets for user %s found in namespace %s. That may be caused by reinstalling product without user namespaces cleanup or using multiple instances of product with the same namespace namings template.", secret.getMetadata().getAnnotations().get(ANNOTATION_USER_NAME), secret.getMetadata().getNamespace()));
            }
            HashMap<String, String> newGitConfigMapData = new HashMap<>(gitConfigMapData);
            newGitConfigMapData.put(GitConfigProvisioner.GIT_CONFIG, gitConfig + String.format(GIT_CREDENTIALS_FILE_STORE_PATTERN, gitSecretFilePath.toString()));
            gitConfigMap.setData(newGitConfigMapData);
        }
    }
}
Also used : Path(java.nio.file.Path) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) HashMap(java.util.HashMap) InfrastructureException(org.eclipse.che.api.workspace.server.spi.InfrastructureException)

Example 5 with InfrastructureException

use of org.eclipse.che.api.workspace.server.spi.InfrastructureException in project che-server by eclipse-che.

the class OpenShiftProjectTest method testOpenShiftProjectCleaningUpIfExceptionsOccurs.

@Test
public void testOpenShiftProjectCleaningUpIfExceptionsOccurs() throws Exception {
    doThrow(new InfrastructureException("err1.")).when(services).delete();
    doThrow(new InfrastructureException("err2.")).when(deployments).delete();
    InfrastructureException error = null;
    // when
    try {
        openShiftProject.cleanUp();
    } catch (InfrastructureException e) {
        error = e;
    }
    // then
    assertNotNull(error);
    String message = error.getMessage();
    assertEquals(message, "Error(s) occurs while cleaning up the namespace. err1. err2.");
    verify(routes).delete();
}
Also used : ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) InfrastructureException(org.eclipse.che.api.workspace.server.spi.InfrastructureException) Test(org.testng.annotations.Test)

Aggregations

InfrastructureException (org.eclipse.che.api.workspace.server.spi.InfrastructureException)242 InternalInfrastructureException (org.eclipse.che.api.workspace.server.spi.InternalInfrastructureException)64 Test (org.testng.annotations.Test)56 KubernetesInfrastructureException (org.eclipse.che.workspace.infrastructure.kubernetes.KubernetesInfrastructureException)44 RuntimeIdentity (org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity)42 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)38 CompletableFuture (java.util.concurrent.CompletableFuture)36 ExecutionException (java.util.concurrent.ExecutionException)36 TimeoutException (java.util.concurrent.TimeoutException)32 ServerException (org.eclipse.che.api.core.ServerException)32 Pod (io.fabric8.kubernetes.api.model.Pod)30 Map (java.util.Map)26 ValidationException (org.eclipse.che.api.core.ValidationException)22 Traced (org.eclipse.che.commons.annotation.Traced)20 Container (io.fabric8.kubernetes.api.model.Container)18 List (java.util.List)18 Set (java.util.Set)18 Inject (javax.inject.Inject)18 RuntimeStartInterruptedException (org.eclipse.che.api.workspace.server.spi.RuntimeStartInterruptedException)18 KubernetesEnvironment (org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment)18