Repository: knox Updated Branches: refs/heads/master d303eee27 -> cbf35dfb0
KNOX-1112 - Knox Shell topology resource management support Project: http://git-wip-us.apache.org/repos/asf/knox/repo Commit: http://git-wip-us.apache.org/repos/asf/knox/commit/cbf35dfb Tree: http://git-wip-us.apache.org/repos/asf/knox/tree/cbf35dfb Diff: http://git-wip-us.apache.org/repos/asf/knox/diff/cbf35dfb Branch: refs/heads/master Commit: cbf35dfb023bf5ec66a0663ba695cf9ee37a5aa7 Parents: d303eee Author: Phil Zampino <[email protected]> Authored: Tue Jul 31 09:11:00 2018 -0400 Committer: Phil Zampino <[email protected]> Committed: Tue Jul 31 13:00:39 2018 -0400 ---------------------------------------------------------------------- .../samples/ExampleManagerListResources.groovy | 53 +++++++++++ .../ExampleManagerResourceDeployment.groovy | 92 ++++++++++++++++++++ .../resources/samples/sample-descriptor.json | 8 ++ .../resources/samples/sample-providers.json | 19 ++++ .../org/apache/knox/gateway/shell/Shell.java | 4 +- .../shell/manager/DeployResourceRequest.java | 83 ++++++++++++++++++ .../shell/manager/ListDescriptorsRequest.java | 27 ++++++ .../ListProviderConfigurationsRequest.java | 27 ++++++ .../shell/manager/ListResourcesRequest.java | 74 ++++++++++++++++ .../shell/manager/ListTopologiesRequest.java | 56 ++++++++++++ .../knox/gateway/shell/manager/Manager.java | 64 ++++++++++++++ .../gateway/shell/manager/ResourceType.java | 35 ++++++++ .../shell/manager/UndeployResourceRequest.java | 52 +++++++++++ 13 files changed, 593 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/knox/blob/cbf35dfb/gateway-shell-samples/src/main/resources/samples/ExampleManagerListResources.groovy ---------------------------------------------------------------------- diff --git a/gateway-shell-samples/src/main/resources/samples/ExampleManagerListResources.groovy b/gateway-shell-samples/src/main/resources/samples/ExampleManagerListResources.groovy new file mode 100644 index 0000000..b995ef3 --- /dev/null +++ b/gateway-shell-samples/src/main/resources/samples/ExampleManagerListResources.groovy @@ -0,0 +1,53 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import org.apache.knox.gateway.shell.Hadoop +import org.apache.knox.gateway.shell.manager.Manager +import org.apache.knox.gateway.shell.Credentials + +gateway = "https://localhost:8443/gateway" + +credentials = new Credentials() +credentials.add("ClearInput", "Enter username: ", "user") + .add("HiddenInput", "Enter pas" + "sword: ", "pass") +credentials.collect() + +username = credentials.get("user").string() +pass = credentials.get("pass").string() + +session = Hadoop.login( gateway, username, pass ) + +List<String> pcs = Manager.listProviderConfigurations(session); +System.out.println("Provider Configurations") +for (String pc : pcs) { + System.out.println(" \u2022 " + pc) +} + +List<String> descs = Manager.listDescriptors(session); +System.out.println("Descriptors") +for (String desc : descs) { + System.out.println(" \u2022 " + desc) +} + +List<String> topos = Manager.listTopologies(session); +System.out.println("Topologies") +for (String topo : topos) { + System.out.println(" \u2022 " + topo) +} + +session.shutdown() http://git-wip-us.apache.org/repos/asf/knox/blob/cbf35dfb/gateway-shell-samples/src/main/resources/samples/ExampleManagerResourceDeployment.groovy ---------------------------------------------------------------------- diff --git a/gateway-shell-samples/src/main/resources/samples/ExampleManagerResourceDeployment.groovy b/gateway-shell-samples/src/main/resources/samples/ExampleManagerResourceDeployment.groovy new file mode 100644 index 0000000..db7d86d --- /dev/null +++ b/gateway-shell-samples/src/main/resources/samples/ExampleManagerResourceDeployment.groovy @@ -0,0 +1,92 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import org.apache.knox.gateway.shell.Hadoop +import org.apache.knox.gateway.shell.manager.Manager +import org.apache.knox.gateway.shell.Credentials + +GATEWAY = "https://localhost:8443/gateway" +SAMPLES_DIR = "./samples" +SAMPLE_PROVIDER_CONFIG_SOURCE = SAMPLES_DIR + "/sample-providers.json" +SAMPLE_DESCRIPTOR_SOURCE = SAMPLES_DIR + "/sample-descriptor.json" + +credentials = new Credentials() +credentials.add("ClearInput", "Enter username: ", "user") + .add("HiddenInput", "Enter pas" + "sword: ", "pass") +credentials.collect() + +username = credentials.get("user").string() +pass = credentials.get("pass").string() + +session = Hadoop.login( GATEWAY, username, pass ) + +// Present the existing provider configurations +List<String> pcs = Manager.listProviderConfigurations(session); +System.out.println("\nExisting Provider Configurations") +for (String pc : pcs) { + System.out.println(" \u2022 " + pc) +} + +// Deploy a new provider configuration +Manager.deployProviderConfiguration(session, "sample-providers", SAMPLE_PROVIDER_CONFIG_SOURCE) + +// Present the updated set of provider configurations +pcs = Manager.listProviderConfigurations(session); +System.out.println("\nProvider Configurations After Deployment") +for (String pc : pcs) { + System.out.println(" \u2022 " + pc) +} + +// Present the set of existing descriptors +List<String> descs = Manager.listDescriptors(session); +System.out.println("\nExisting Descriptors") +for (String desc : descs) { + System.out.println(" \u2022 " + desc) +} + +// Deploy a new descriptor +Manager.deployDescriptor(session, "sample", SAMPLE_DESCRIPTOR_SOURCE) + +// Present the set of descriptors, showing that the deployment succeeded +descs = Manager.listDescriptors(session); +System.out.println("\nDescriptors After Deployment") +for (String desc : descs) { + System.out.println(" \u2022 " + desc) +} + +Manager.undeployDescriptor(session, "sample") + +// Present the set of descriptors, showing that the undeployment succeeded +descs = Manager.listDescriptors(session); +System.out.println("\nDescriptors After Undeployment") +for (String desc : descs) { + System.out.println(" \u2022 " + desc) +} + +Manager.undeployProviderConfiguration(session, "sample-providers") + +// Present the set of provider configurations, showing that the undeployment succeeded +pcs = Manager.listProviderConfigurations(session); +System.out.println("\nProvider Configurations After Undeployment") +for (String pc : pcs) { + System.out.println(" \u2022 " + pc) +} + +System.out.println(); + +session.shutdown() http://git-wip-us.apache.org/repos/asf/knox/blob/cbf35dfb/gateway-shell-samples/src/main/resources/samples/sample-descriptor.json ---------------------------------------------------------------------- diff --git a/gateway-shell-samples/src/main/resources/samples/sample-descriptor.json b/gateway-shell-samples/src/main/resources/samples/sample-descriptor.json new file mode 100644 index 0000000..697d046 --- /dev/null +++ b/gateway-shell-samples/src/main/resources/samples/sample-descriptor.json @@ -0,0 +1,8 @@ +{ + "provider-config-ref":"default-providers", + "services":[ + {"name":"NAMENODE"}, + {"name":"WEBHDFS"}, + {"name":"RESOURCEMANAGER"} + ] +} http://git-wip-us.apache.org/repos/asf/knox/blob/cbf35dfb/gateway-shell-samples/src/main/resources/samples/sample-providers.json ---------------------------------------------------------------------- diff --git a/gateway-shell-samples/src/main/resources/samples/sample-providers.json b/gateway-shell-samples/src/main/resources/samples/sample-providers.json new file mode 100644 index 0000000..530d9a6 --- /dev/null +++ b/gateway-shell-samples/src/main/resources/samples/sample-providers.json @@ -0,0 +1,19 @@ +{ + "providers": [ + { + "role": "authentication", + "name": "ShiroProvider", + "enabled": "true", + "params": { + "sessionTimeout": "20", + "main.ldapRealm": "org.apache.knox.gateway.shirorealm.KnoxLdapRealm", + "main.ldapContextFactory": "org.apache.knox.gateway.shirorealm.KnoxLdapContextFactory", + "main.ldapRealm.contextFactory": "$ldapContextFactory", + "main.ldapRealm.userDnTemplate": "uid={0},ou=people,dc=hadoop,dc=apache,dc=org", + "main.ldapRealm.contextFactory.url": "ldap://localhost:33389", + "main.ldapRealm.contextFactory.authenticationMechanism": "simple", + "urls./**": "authcBasic" + } + } + ] +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/knox/blob/cbf35dfb/gateway-shell/src/main/java/org/apache/knox/gateway/shell/Shell.java ---------------------------------------------------------------------- diff --git a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/Shell.java b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/Shell.java index c91faf7..714f9cf 100644 --- a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/Shell.java +++ b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/Shell.java @@ -21,6 +21,7 @@ import groovy.ui.GroovyMain; import org.apache.knox.gateway.shell.hbase.HBase; import org.apache.knox.gateway.shell.hdfs.Hdfs; import org.apache.knox.gateway.shell.job.Job; +import org.apache.knox.gateway.shell.manager.Manager; import org.apache.knox.gateway.shell.workflow.Workflow; import org.apache.knox.gateway.shell.yarn.Yarn; import org.apache.log4j.PropertyConfigurator; @@ -41,7 +42,8 @@ public class Shell { Job.class.getName(), Workflow.class.getName(), Yarn.class.getName(), - TimeUnit.class.getName() + TimeUnit.class.getName(), + Manager.class.getName() }; static { http://git-wip-us.apache.org/repos/asf/knox/blob/cbf35dfb/gateway-shell/src/main/java/org/apache/knox/gateway/shell/manager/DeployResourceRequest.java ---------------------------------------------------------------------- diff --git a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/manager/DeployResourceRequest.java b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/manager/DeployResourceRequest.java new file mode 100644 index 0000000..eae35c9 --- /dev/null +++ b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/manager/DeployResourceRequest.java @@ -0,0 +1,83 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.apache.knox.gateway.shell.manager; + + +import org.apache.http.HttpEntity; +import org.apache.http.client.methods.HttpPut; +import org.apache.http.client.utils.URIBuilder; +import org.apache.http.entity.ContentType; +import org.apache.http.entity.FileEntity; +import org.apache.knox.gateway.shell.AbstractRequest; +import org.apache.knox.gateway.shell.BasicResponse; +import org.apache.knox.gateway.shell.Hadoop; + +import java.io.File; +import java.io.FileNotFoundException; +import java.util.List; +import java.util.concurrent.Callable; + +class DeployResourceRequest extends AbstractRequest<BasicResponse> { + + private ResourceType resourceType = null; + private String resourceName = null; + private String resourceFileName = null; + + + DeployResourceRequest(Hadoop session, ResourceType type, String name, String resourceFileName) { + super(session); + this.resourceType = type; + this.resourceName = name; + this.resourceFileName = resourceFileName; + } + + public void execute() throws Exception { + if (isExistingResource()) { + throw new IllegalStateException("A " + resourceType.getName() + " resource with the same name (" + resourceName + ") is already deployed."); + } else { + callable().call(); + } + } + + @Override + protected Callable<BasicResponse> callable() { + return () -> { + URIBuilder uri = uri( "/admin/api/v1/", resourceType.getName(), "/", resourceName ); + HttpPut request = new HttpPut( uri.build() ); + + if (resourceFileName != null) { + File resource = new File(resourceFileName); + if (!resource.exists()) { + throw new FileNotFoundException(resourceFileName); + } + HttpEntity entity = new FileEntity(new File(resourceFileName), ContentType.APPLICATION_JSON); + request.setEntity(entity); + } + return new BasicResponse( execute( request ) ); + }; + } + + private boolean isExistingResource() throws Exception { + boolean result = false; + List<String> existing = (new ListResourcesRequest(hadoop(), resourceType)).execute(); + if (existing != null) { + result = existing.contains(resourceName); + } + return result; + } + +} http://git-wip-us.apache.org/repos/asf/knox/blob/cbf35dfb/gateway-shell/src/main/java/org/apache/knox/gateway/shell/manager/ListDescriptorsRequest.java ---------------------------------------------------------------------- diff --git a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/manager/ListDescriptorsRequest.java b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/manager/ListDescriptorsRequest.java new file mode 100644 index 0000000..02505cc --- /dev/null +++ b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/manager/ListDescriptorsRequest.java @@ -0,0 +1,27 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.apache.knox.gateway.shell.manager; + +import org.apache.knox.gateway.shell.Hadoop; + +class ListDescriptorsRequest extends ListResourcesRequest { + + ListDescriptorsRequest(Hadoop session) { + super(session, ResourceType.Descriptor); + } + +} http://git-wip-us.apache.org/repos/asf/knox/blob/cbf35dfb/gateway-shell/src/main/java/org/apache/knox/gateway/shell/manager/ListProviderConfigurationsRequest.java ---------------------------------------------------------------------- diff --git a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/manager/ListProviderConfigurationsRequest.java b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/manager/ListProviderConfigurationsRequest.java new file mode 100644 index 0000000..d7b50f8 --- /dev/null +++ b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/manager/ListProviderConfigurationsRequest.java @@ -0,0 +1,27 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.apache.knox.gateway.shell.manager; + +import org.apache.knox.gateway.shell.Hadoop; + +class ListProviderConfigurationsRequest extends ListResourcesRequest { + + ListProviderConfigurationsRequest(Hadoop session) { + super(session, ResourceType.ProviderConfiguration); + } + +} http://git-wip-us.apache.org/repos/asf/knox/blob/cbf35dfb/gateway-shell/src/main/java/org/apache/knox/gateway/shell/manager/ListResourcesRequest.java ---------------------------------------------------------------------- diff --git a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/manager/ListResourcesRequest.java b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/manager/ListResourcesRequest.java new file mode 100644 index 0000000..79b1f19 --- /dev/null +++ b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/manager/ListResourcesRequest.java @@ -0,0 +1,74 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.apache.knox.gateway.shell.manager; + +import net.minidev.json.JSONArray; +import net.minidev.json.JSONObject; +import net.minidev.json.parser.JSONParser; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.utils.URIBuilder; +import org.apache.knox.gateway.shell.AbstractRequest; +import org.apache.knox.gateway.shell.BasicResponse; +import org.apache.knox.gateway.shell.Hadoop; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.Callable; + +class ListResourcesRequest extends AbstractRequest<BasicResponse> { + + private ResourceType resourceType = null; + + ListResourcesRequest(Hadoop session, ResourceType resourceType) { + super(session); + this.resourceType = resourceType; + } + + public List<String> execute() throws Exception { + return parseResourceNames( callable().call() ); + } + + @Override + protected Callable<BasicResponse> callable() { + return () -> { + URIBuilder uri = uri( "/admin/api/v1/", resourceType.getName() ); + HttpGet request = new HttpGet( uri.build() ); + request.setHeader("Accept", "application/json"); + return new BasicResponse( execute( request ) ); + }; + } + + protected List<String> parseResourceNames(BasicResponse response) throws Exception { + List<String> result = new ArrayList<>(); + JSONObject json = (JSONObject) new JSONParser(0).parse(response.getBytes()); + if (json != null) { + JSONArray items = (JSONArray) json.get("items"); + if (items != null) { + for (int i = 0; i < items.size(); i++) { + JSONObject item = (JSONObject) items.get(i); + String name = (String) item.get("name"); + if (name != null) { + result.add(name.substring(0, name.lastIndexOf("."))); + } + } + } + } + return result; + } + + +} http://git-wip-us.apache.org/repos/asf/knox/blob/cbf35dfb/gateway-shell/src/main/java/org/apache/knox/gateway/shell/manager/ListTopologiesRequest.java ---------------------------------------------------------------------- diff --git a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/manager/ListTopologiesRequest.java b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/manager/ListTopologiesRequest.java new file mode 100644 index 0000000..acffdd0 --- /dev/null +++ b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/manager/ListTopologiesRequest.java @@ -0,0 +1,56 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.apache.knox.gateway.shell.manager; + +import net.minidev.json.JSONArray; +import net.minidev.json.JSONObject; +import net.minidev.json.parser.JSONParser; +import org.apache.knox.gateway.shell.BasicResponse; +import org.apache.knox.gateway.shell.Hadoop; + +import java.util.ArrayList; +import java.util.List; + +class ListTopologiesRequest extends ListResourcesRequest { + + ListTopologiesRequest(Hadoop session) { + super(session, ResourceType.Topology); + } + + @Override + protected List<String> parseResourceNames(BasicResponse response) throws Exception { + List<String> result = new ArrayList<>(); + JSONObject json = (JSONObject) new JSONParser(0).parse(response.getBytes()); + if (json != null) { + JSONObject topologies = (JSONObject) json.get("topologies"); + if (topologies != null) { + JSONArray items = (JSONArray) topologies.get("topology"); + if (items != null) { + for (int i = 0; i < items.size(); i++) { + JSONObject item = (JSONObject) items.get(i); + String name = (String) item.get("name"); + if (name != null) { + result.add(name); + } + } + } + } + } + return result; + } + +} http://git-wip-us.apache.org/repos/asf/knox/blob/cbf35dfb/gateway-shell/src/main/java/org/apache/knox/gateway/shell/manager/Manager.java ---------------------------------------------------------------------- diff --git a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/manager/Manager.java b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/manager/Manager.java new file mode 100644 index 0000000..8dbf2a8 --- /dev/null +++ b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/manager/Manager.java @@ -0,0 +1,64 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.apache.knox.gateway.shell.manager; + +import org.apache.knox.gateway.shell.Hadoop; + +import java.util.List; + +/** + * Manages topology-related resources + */ +public class Manager { + + public static List<String> listDescriptors(Hadoop session) throws Exception { + return (new ListDescriptorsRequest(session)).execute(); + } + + + public static void deployDescriptor(Hadoop session, String name, String descriptorFileName) throws Exception { + (new DeployResourceRequest(session, ResourceType.Descriptor, name, descriptorFileName)).execute(); + } + + + public static void undeployDescriptor(Hadoop session, String name) throws Exception { + (new UndeployResourceRequest(session, ResourceType.Descriptor, name)).execute(); + } + + + public static List<String> listProviderConfigurations(Hadoop session) throws Exception { + return (new ListProviderConfigurationsRequest(session)).execute(); + } + + + public static void deployProviderConfiguration(Hadoop session, + String name, + String providerConfigFileName) throws Exception { + (new DeployResourceRequest(session, ResourceType.ProviderConfiguration, name, providerConfigFileName)).execute(); + } + + + public static void undeployProviderConfiguration(Hadoop session, String name) throws Exception { + (new UndeployResourceRequest(session, ResourceType.ProviderConfiguration, name)).execute(); + } + + + public static List<String> listTopologies(Hadoop session) throws Exception { + return (new ListTopologiesRequest(session)).execute(); + } + +} http://git-wip-us.apache.org/repos/asf/knox/blob/cbf35dfb/gateway-shell/src/main/java/org/apache/knox/gateway/shell/manager/ResourceType.java ---------------------------------------------------------------------- diff --git a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/manager/ResourceType.java b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/manager/ResourceType.java new file mode 100644 index 0000000..7a3eb39 --- /dev/null +++ b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/manager/ResourceType.java @@ -0,0 +1,35 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.apache.knox.gateway.shell.manager; + +public class ResourceType { + + public static final ResourceType ProviderConfiguration = new ResourceType("providerconfig"); + public static final ResourceType Descriptor = new ResourceType("descriptors"); + public static final ResourceType Topology = new ResourceType("topologies"); + + private String name = null; + + private ResourceType(String type) { + this.name = type; + } + + public String getName() { + return name; + } + +} http://git-wip-us.apache.org/repos/asf/knox/blob/cbf35dfb/gateway-shell/src/main/java/org/apache/knox/gateway/shell/manager/UndeployResourceRequest.java ---------------------------------------------------------------------- diff --git a/gateway-shell/src/main/java/org/apache/knox/gateway/shell/manager/UndeployResourceRequest.java b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/manager/UndeployResourceRequest.java new file mode 100644 index 0000000..b4af909 --- /dev/null +++ b/gateway-shell/src/main/java/org/apache/knox/gateway/shell/manager/UndeployResourceRequest.java @@ -0,0 +1,52 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.apache.knox.gateway.shell.manager; + +import org.apache.http.client.methods.HttpDelete; +import org.apache.http.client.utils.URIBuilder; +import org.apache.knox.gateway.shell.AbstractRequest; +import org.apache.knox.gateway.shell.BasicResponse; +import org.apache.knox.gateway.shell.Hadoop; + +import java.util.concurrent.Callable; + +class UndeployResourceRequest extends AbstractRequest<BasicResponse> { + + private ResourceType resourceType = null; + private String resourceName = null; + + + UndeployResourceRequest(Hadoop session, ResourceType type, String name) { + super(session); + this.resourceType = type; + this.resourceName = name; + } + + public void execute() throws Exception { + callable().call(); + } + + @Override + protected Callable<BasicResponse> callable() { + return () -> { + URIBuilder uri = uri( "/admin/api/v1/", resourceType.getName(), "/", resourceName ); + HttpDelete request = new HttpDelete( uri.build() ); + return new BasicResponse( execute( request ) ); + }; + } + +}
