-
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.
Add an ability to list available k8s namespaces
Signed-off-by: Sergii Leshchenko <sleshche@redhat.com>
- Loading branch information
1 parent
10c9c24
commit 82ea302
Showing
14 changed files
with
873 additions
and
0 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
67 changes: 67 additions & 0 deletions
67
...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,67 @@ | ||
/* | ||
* 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 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") | ||
public class KubernetesNamespaceService extends Service { | ||
|
||
private final KubernetesNamespaceFactory namespaceFactory; | ||
|
||
@Inject | ||
public KubernetesNamespaceService(KubernetesNamespaceFactory namespaceFactory) { | ||
this.namespaceFactory = namespaceFactory; | ||
} | ||
|
||
@GET | ||
@Produces(APPLICATION_JSON) | ||
@ApiOperation( | ||
value = "Get existing k8s namespaces where user is able to create workspaces", | ||
notes = "This operation can be performed only by authorized user", | ||
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 | ||
+ '}'; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...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,27 @@ | ||
/* | ||
* 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 { | ||
/** Returns the name of namespace. */ | ||
String getName(); | ||
|
||
/** Returns namespace attributes, which may contains additional info about it like description. */ | ||
Map<String, String> getAttributes(); | ||
} |
32 changes: 32 additions & 0 deletions
32
...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,32 @@ | ||
/* | ||
* 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.workspace.infrastructure.kubernetes.api.shared.KubernetesNamespaceMeta; | ||
|
||
/** @author Sergii Leshchenko */ | ||
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); | ||
} |
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
Oops, something went wrong.