-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added an ability to list namespace available to ws creation
Signed-off-by: Sergii Leshchenko <[email protected]>
- Loading branch information
1 parent
fc55053
commit b7de42c
Showing
14 changed files
with
1,184 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
...clipse/che/workspace/infrastructure/kubernetes/api/server/KubernetesNamespaceService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* Copyright (c) 2012-2018 Red Hat, Inc. | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
*/ | ||
package org.eclipse.che.workspace.infrastructure.kubernetes.api.server; | ||
|
||
import static javax.ws.rs.core.MediaType.APPLICATION_JSON; | ||
|
||
import com.google.common.annotations.Beta; | ||
import io.swagger.annotations.Api; | ||
import io.swagger.annotations.ApiOperation; | ||
import io.swagger.annotations.ApiResponse; | ||
import io.swagger.annotations.ApiResponses; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import javax.inject.Inject; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.Produces; | ||
import org.eclipse.che.api.core.rest.Service; | ||
import org.eclipse.che.api.workspace.server.spi.InfrastructureException; | ||
import org.eclipse.che.dto.server.DtoFactory; | ||
import org.eclipse.che.workspace.infrastructure.kubernetes.api.shared.KubernetesNamespaceMeta; | ||
import org.eclipse.che.workspace.infrastructure.kubernetes.api.shared.dto.KubernetesNamespaceMetaDto; | ||
import org.eclipse.che.workspace.infrastructure.kubernetes.namespace.KubernetesNamespaceFactory; | ||
|
||
/** @author Sergii Leshchenko */ | ||
@Api( | ||
value = "kubernetes-namespace", | ||
description = "Kubernetes REST API for working with Namespaces") | ||
@Path("/kubernetes/namespace") | ||
@Beta | ||
public class KubernetesNamespaceService extends Service { | ||
|
||
private final KubernetesNamespaceFactory namespaceFactory; | ||
|
||
@Inject | ||
public KubernetesNamespaceService(KubernetesNamespaceFactory namespaceFactory) { | ||
this.namespaceFactory = namespaceFactory; | ||
} | ||
|
||
@GET | ||
@Produces(APPLICATION_JSON) | ||
@ApiOperation( | ||
value = "Get k8s namespaces where user is able to create workspaces", | ||
notes = | ||
"This operation can be performed only by authorized user." | ||
+ "This is under beta and may be significant changed", | ||
response = String.class, | ||
responseContainer = "List") | ||
@ApiResponses({ | ||
@ApiResponse(code = 200, message = "The namespaces successfully fetched"), | ||
@ApiResponse(code = 500, message = "Internal server error occurred during namespaces fetching") | ||
}) | ||
public List<KubernetesNamespaceMetaDto> getNamespaces() throws InfrastructureException { | ||
return namespaceFactory.list().stream().map(this::asDto).collect(Collectors.toList()); | ||
} | ||
|
||
private KubernetesNamespaceMetaDto asDto(KubernetesNamespaceMeta kubernetesNamespaceMeta) { | ||
return DtoFactory.newDto(KubernetesNamespaceMetaDto.class) | ||
.withName(kubernetesNamespaceMeta.getName()) | ||
.withAttributes(kubernetesNamespaceMeta.getAttributes()); | ||
} | ||
} |
85 changes: 85 additions & 0 deletions
85
...che/workspace/infrastructure/kubernetes/api/server/impls/KubernetesNamespaceMetaImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
* Copyright (c) 2012-2018 Red Hat, Inc. | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
*/ | ||
package org.eclipse.che.workspace.infrastructure.kubernetes.api.server.impls; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
import org.eclipse.che.workspace.infrastructure.kubernetes.api.shared.KubernetesNamespaceMeta; | ||
|
||
/** @author Sergii Leshchenko */ | ||
public class KubernetesNamespaceMetaImpl implements KubernetesNamespaceMeta { | ||
|
||
private String name; | ||
private Map<String, String> attributes; | ||
|
||
public KubernetesNamespaceMetaImpl(String name) { | ||
this.name = name; | ||
} | ||
|
||
public KubernetesNamespaceMetaImpl(String name, Map<String, String> attributes) { | ||
this.name = name; | ||
if (attributes != null) { | ||
this.attributes = new HashMap<>(attributes); | ||
} | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
@Override | ||
public Map<String, String> getAttributes() { | ||
if (attributes == null) { | ||
attributes = new HashMap<>(); | ||
} | ||
return attributes; | ||
} | ||
|
||
public void setAttributes(Map<String, String> attributes) { | ||
this.attributes = attributes; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (!(o instanceof KubernetesNamespaceMetaImpl)) { | ||
return false; | ||
} | ||
KubernetesNamespaceMetaImpl that = (KubernetesNamespaceMetaImpl) o; | ||
return Objects.equals(getName(), that.getName()) | ||
&& Objects.equals(getAttributes(), that.getAttributes()); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(getName(), getAttributes()); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "KubernetesNamespaceMetaImpl{" | ||
+ "name='" | ||
+ name | ||
+ '\'' | ||
+ ", attributes=" | ||
+ attributes | ||
+ '}'; | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
...g/eclipse/che/workspace/infrastructure/kubernetes/api/shared/KubernetesNamespaceMeta.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright (c) 2012-2018 Red Hat, Inc. | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
*/ | ||
package org.eclipse.che.workspace.infrastructure.kubernetes.api.shared; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* Describes meta information about kubernetes namespace. | ||
* | ||
* @author Sergii Leshchenko | ||
*/ | ||
public interface KubernetesNamespaceMeta { | ||
|
||
/** | ||
* Attribute that shows if k8s namespace is configured as default. Possible values: true/false. | ||
* Absent value should be considered as false. | ||
*/ | ||
String DEFAULT_ATTRIBUTE = "default"; | ||
|
||
/** | ||
* Attributes that contains information about current namespace status. Example values: Active, | ||
* Terminating. Absent value indicates that namespace is not created yet. | ||
*/ | ||
String PHASE_ATTRIBUTE = "phase"; | ||
|
||
/** | ||
* Returns the name of namespace. | ||
* | ||
* <p>Value may be not a name of existing namespace, but predicted name with placeholders inside, | ||
* like <workspaceid>. | ||
*/ | ||
String getName(); | ||
|
||
/** Returns namespace attributes, which may contains additional info about it like description. */ | ||
Map<String, String> getAttributes(); | ||
} |
34 changes: 34 additions & 0 deletions
34
...se/che/workspace/infrastructure/kubernetes/api/shared/dto/KubernetesNamespaceMetaDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright (c) 2012-2018 Red Hat, Inc. | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
*/ | ||
package org.eclipse.che.workspace.infrastructure.kubernetes.api.shared.dto; | ||
|
||
import java.util.Map; | ||
import org.eclipse.che.dto.shared.DTO; | ||
import org.eclipse.che.workspace.infrastructure.kubernetes.api.shared.KubernetesNamespaceMeta; | ||
|
||
/** @author Sergii Leshchenko */ | ||
@DTO | ||
public interface KubernetesNamespaceMetaDto extends KubernetesNamespaceMeta { | ||
@Override | ||
String getName(); | ||
|
||
void setName(String name); | ||
|
||
KubernetesNamespaceMetaDto withName(String name); | ||
|
||
@Override | ||
Map<String, String> getAttributes(); | ||
|
||
void setAttributes(Map<String, String> attributes); | ||
|
||
KubernetesNamespaceMetaDto withAttributes(Map<String, String> attributes); | ||
} |
Oops, something went wrong.