From aa7cacf9c99a275796ba02ec14efac5390037695 Mon Sep 17 00:00:00 2001 From: Vitalii Parfonov Date: Mon, 20 Jul 2020 18:19:11 +0300 Subject: [PATCH] Various fixes after meging PR #16972 Signed-off-by: Vitalii Parfonov --- .../openshift/AsyncStorageModeValidator.java | 19 ++++++++++++------- .../provision/AsyncStorageProvisioner.java | 14 +++++++++----- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/infrastructures/openshift/src/main/java/org/eclipse/che/workspace/infrastructure/openshift/AsyncStorageModeValidator.java b/infrastructures/openshift/src/main/java/org/eclipse/che/workspace/infrastructure/openshift/AsyncStorageModeValidator.java index a0cff2c0401..f7461ec1b57 100644 --- a/infrastructures/openshift/src/main/java/org/eclipse/che/workspace/infrastructure/openshift/AsyncStorageModeValidator.java +++ b/infrastructures/openshift/src/main/java/org/eclipse/che/workspace/infrastructure/openshift/AsyncStorageModeValidator.java @@ -11,13 +11,13 @@ */ package org.eclipse.che.workspace.infrastructure.openshift; +import static com.google.common.base.Strings.isNullOrEmpty; import static java.lang.Boolean.parseBoolean; import static java.lang.String.format; import static org.eclipse.che.api.workspace.shared.Constants.ASYNC_PERSIST_ATTRIBUTE; import static org.eclipse.che.workspace.infrastructure.kubernetes.namespace.pvc.CommonPVCStrategy.COMMON_STRATEGY; import static org.eclipse.che.workspace.infrastructure.kubernetes.namespace.pvc.EphemeralWorkspaceUtility.isEphemeral; -import com.google.common.base.Strings; import java.util.Map; import javax.inject.Inject; import javax.inject.Named; @@ -57,8 +57,10 @@ public class AsyncStorageModeValidator implements WorkspaceAttributeValidator { private final String pvcStrategy; private final boolean allowUserDefinedNamespaces; - private final String defaultNamespaceName; private final int runtimesPerUser; + private final boolean isNamespaceStrategyNotValid; + private final boolean isPvcStrategyNotValid; + private final boolean runtimesPerUserLimited; @Inject public AsyncStorageModeValidator( @@ -70,8 +72,12 @@ public AsyncStorageModeValidator( this.pvcStrategy = pvcStrategy; this.allowUserDefinedNamespaces = allowUserDefinedNamespaces; - this.defaultNamespaceName = defaultNamespaceName; this.runtimesPerUser = runtimesPerUser; + + this.isPvcStrategyNotValid = !COMMON_STRATEGY.equals(pvcStrategy); + this.runtimesPerUserLimited = runtimesPerUser > 1; + this.isNamespaceStrategyNotValid = + isNullOrEmpty(defaultNamespaceName) || !defaultNamespaceName.contains(""); } @Override @@ -114,7 +120,7 @@ private void isEphemeralAttributeValidation(Map attributes) } private void runtimesPerUserValidation() throws ValidationException { - if (runtimesPerUser > 1) { + if (runtimesPerUserLimited) { String message = format( "Workspace configuration not valid: Asynchronous storage available only if 'che.limits.user.workspaces.run.count' set to 1, but got %s", @@ -125,8 +131,7 @@ private void runtimesPerUserValidation() throws ValidationException { } private void nameSpaceStrategyValidation() throws ValidationException { - if (Strings.isNullOrEmpty(defaultNamespaceName) - || !defaultNamespaceName.contains("")) { + if (isNamespaceStrategyNotValid) { String message = "Workspace configuration not valid: Asynchronous storage available only for 'per-user' namespace strategy"; LOG.warn(message); @@ -146,7 +151,7 @@ private void alowUserDefinedNamespaceValidation() throws ValidationException { } private void pvcStrategyValidation() throws ValidationException { - if (!COMMON_STRATEGY.equals(pvcStrategy)) { + if (isPvcStrategyNotValid) { String message = format( "Workspace configuration not valid: Asynchronous storage available only for 'common' PVC strategy, but got %s", diff --git a/infrastructures/openshift/src/main/java/org/eclipse/che/workspace/infrastructure/openshift/provision/AsyncStorageProvisioner.java b/infrastructures/openshift/src/main/java/org/eclipse/che/workspace/infrastructure/openshift/provision/AsyncStorageProvisioner.java index 6af22f963d9..e1801f57b40 100644 --- a/infrastructures/openshift/src/main/java/org/eclipse/che/workspace/infrastructure/openshift/provision/AsyncStorageProvisioner.java +++ b/infrastructures/openshift/src/main/java/org/eclipse/che/workspace/infrastructure/openshift/provision/AsyncStorageProvisioner.java @@ -69,6 +69,7 @@ import org.eclipse.che.api.workspace.server.spi.InfrastructureException; import org.eclipse.che.workspace.infrastructure.kubernetes.Names; import org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesObjectUtil; +import org.eclipse.che.workspace.infrastructure.kubernetes.server.ServerServiceBuilder; import org.eclipse.che.workspace.infrastructure.openshift.OpenShiftClientFactory; import org.eclipse.che.workspace.infrastructure.openshift.environment.OpenShiftEnvironment; import org.slf4j.Logger; @@ -369,15 +370,18 @@ private void createStorageServiceIfNotExist( .withPort(SERVICE_PORT) .withTargetPort(targetPort) .build(); + ServiceSpec spec = new ServiceSpec(); spec.setPorts(singletonList(port)); spec.setSelector(of("app", ASYNC_STORAGE)); - Service service = new Service(); - service.setApiVersion("v1"); - service.setKind("Service"); - service.setMetadata(meta); - service.setSpec(spec); + ServerServiceBuilder serviceBuilder = new ServerServiceBuilder(); + Service service = + serviceBuilder + .withPorts(singletonList(port)) + .withSelectorEntry("app", ASYNC_STORAGE) + .withName(ASYNC_STORAGE) + .build(); oc.services().inNamespace(namespace).create(service); }