diff options
| author | Shireesh Anjal <shireesh@gluster.com> | 2011-11-25 20:13:35 +0530 |
|---|---|---|
| committer | Shireesh Anjal <shireesh@gluster.com> | 2011-11-25 20:13:35 +0530 |
| commit | 1142b0e41de39010de7845cf70d71dbb001fc1dc (patch) | |
| tree | 3513487f65c1a7df47996bd2852393aceaac1b8a /src/com.gluster.storage.management.client | |
| parent | 92c52d8edf285945d31e446503fc742fde9dcc49 (diff) | |
Renamed projects / packages com.gluster.* to org.gluster.*
Diffstat (limited to 'src/com.gluster.storage.management.client')
19 files changed, 0 insertions, 1405 deletions
diff --git a/src/com.gluster.storage.management.client/.classpath b/src/com.gluster.storage.management.client/.classpath deleted file mode 100644 index d81daeeb..00000000 --- a/src/com.gluster.storage.management.client/.classpath +++ /dev/null @@ -1,12 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<classpath> - <classpathentry exported="true" kind="lib" path="lib/jersey-1.5/jersey-multipart-1.5.jar"/> - <classpathentry exported="true" kind="lib" path="keystore/"/> - <classpathentry exported="true" kind="lib" path="lib/jersey-1.5/jersey-client-1.5.jar" sourcepath="/data/downloads/sun/jersey/sources/jersey-client-1.5-sources.jar"/> - <classpathentry exported="true" kind="lib" path="lib/jersey-1.5/jersey-core-1.5.jar" sourcepath="/home/selvam/sources/jersey/jersey-core-1.5-sources.jar"/> - <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/> - <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> - <classpathentry excluding="keystore/" kind="src" path="src"/> - <classpathentry combineaccessrules="false" kind="src" path="/com.gluster.storage.management.core"/> - <classpathentry kind="output" path="bin"/> -</classpath> diff --git a/src/com.gluster.storage.management.client/.project b/src/com.gluster.storage.management.client/.project deleted file mode 100644 index 61a0ec41..00000000 --- a/src/com.gluster.storage.management.client/.project +++ /dev/null @@ -1,34 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<projectDescription> - <name>com.gluster.storage.management.client</name> - <comment></comment> - <projects> - </projects> - <buildSpec> - <buildCommand> - <name>org.eclipse.jdt.core.javabuilder</name> - <arguments> - </arguments> - </buildCommand> - <buildCommand> - <name>org.eclipse.pde.ManifestBuilder</name> - <arguments> - </arguments> - </buildCommand> - <buildCommand> - <name>org.eclipse.pde.SchemaBuilder</name> - <arguments> - </arguments> - </buildCommand> - <buildCommand> - <name>com.instantiations.assist.eclipse.coverage.instrumentationBuilder</name> - <arguments> - </arguments> - </buildCommand> - </buildSpec> - <natures> - <nature>org.eclipse.pde.PluginNature</nature> - <nature>org.eclipse.jdt.core.javanature</nature> - <nature>com.instantiations.assist.eclipse.coverage.codeCoverageNature</nature> - </natures> -</projectDescription> diff --git a/src/com.gluster.storage.management.client/.settings/org.eclipse.jdt.core.prefs b/src/com.gluster.storage.management.client/.settings/org.eclipse.jdt.core.prefs deleted file mode 100644 index f8b5cc38..00000000 --- a/src/com.gluster.storage.management.client/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -1,8 +0,0 @@ -#Wed Dec 29 15:47:13 IST 2010 -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 -org.eclipse.jdt.core.compiler.compliance=1.6 -org.eclipse.jdt.core.compiler.problem.assertIdentifier=error -org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.source=1.6 diff --git a/src/com.gluster.storage.management.client/META-INF/MANIFEST.MF b/src/com.gluster.storage.management.client/META-INF/MANIFEST.MF deleted file mode 100644 index 7958d8cd..00000000 --- a/src/com.gluster.storage.management.client/META-INF/MANIFEST.MF +++ /dev/null @@ -1,17 +0,0 @@ -Manifest-Version: 1.0 -Bundle-ManifestVersion: 2 -Bundle-Name: Gluster Storage Platform Client -Bundle-SymbolicName: com.gluster.storage.management.client -Bundle-Version: 1.0.0 -Bundle-Vendor: GLUSTER -Bundle-RequiredExecutionEnvironment: JavaSE-1.6 -Require-Bundle: com.gluster.storage.management.core;bundle-version="1.0.0", - org.eclipse.equinox.common;bundle-version="3.6.0" -Export-Package: com.gluster.storage.management.client, - com.gluster.storage.management.client.constants -Bundle-ClassPath: ., - lib/jersey-1.5/jersey-client-1.5.jar, - lib/jersey-1.5/jersey-core-1.5.jar, - lib/jersey-1.5/jersey-multipart-1.5.jar, - keystore/ -Import-Package: org.eclipse.jface.preference diff --git a/src/com.gluster.storage.management.client/build.properties b/src/com.gluster.storage.management.client/build.properties deleted file mode 100644 index b9d04dbf..00000000 --- a/src/com.gluster.storage.management.client/build.properties +++ /dev/null @@ -1,14 +0,0 @@ -source.. = src/ -output.. = bin/ -bin.includes = .,\ - META-INF/,\ - lib/,\ - keystore/,\ - lib/jersey-1.5/jersey-multipart-1.5.jar -src.includes = lib/,\ - keystore/,\ - build.properties,\ - .project,\ - .classpath,\ - .settings/,\ - META-INF/ diff --git a/src/com.gluster.storage.management.client/keystore/gmc-trusted.keystore b/src/com.gluster.storage.management.client/keystore/gmc-trusted.keystore Binary files differdeleted file mode 100644 index 5517b6e5..00000000 --- a/src/com.gluster.storage.management.client/keystore/gmc-trusted.keystore +++ /dev/null diff --git a/src/com.gluster.storage.management.client/lib/jersey-1.5/jersey-client-1.5.jar b/src/com.gluster.storage.management.client/lib/jersey-1.5/jersey-client-1.5.jar Binary files differdeleted file mode 100644 index 62f790fa..00000000 --- a/src/com.gluster.storage.management.client/lib/jersey-1.5/jersey-client-1.5.jar +++ /dev/null diff --git a/src/com.gluster.storage.management.client/lib/jersey-1.5/jersey-core-1.5.jar b/src/com.gluster.storage.management.client/lib/jersey-1.5/jersey-core-1.5.jar Binary files differdeleted file mode 100644 index 92b38466..00000000 --- a/src/com.gluster.storage.management.client/lib/jersey-1.5/jersey-core-1.5.jar +++ /dev/null diff --git a/src/com.gluster.storage.management.client/lib/jersey-1.5/jersey-multipart-1.5.jar b/src/com.gluster.storage.management.client/lib/jersey-1.5/jersey-multipart-1.5.jar Binary files differdeleted file mode 100644 index 1c134f05..00000000 --- a/src/com.gluster.storage.management.client/lib/jersey-1.5/jersey-multipart-1.5.jar +++ /dev/null diff --git a/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/AbstractClient.java b/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/AbstractClient.java deleted file mode 100644 index a77e2a31..00000000 --- a/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/AbstractClient.java +++ /dev/null @@ -1,428 +0,0 @@ -package com.gluster.storage.management.client;
-
-import static com.gluster.storage.management.client.constants.ClientConstants.ALGORITHM_SUNX509;
-import static com.gluster.storage.management.client.constants.ClientConstants.KEYSTORE_TYPE_JKS;
-import static com.gluster.storage.management.client.constants.ClientConstants.PROTOCOL_TLS;
-import static com.gluster.storage.management.client.constants.ClientConstants.TRUSTED_KEYSTORE;
-import static com.gluster.storage.management.client.constants.ClientConstants.TRUSTED_KEYSTORE_ACCESS;
-
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.ConnectException;
-import java.net.URI;
-import java.security.KeyStore;
-
-import javax.net.ssl.HostnameVerifier;
-import javax.net.ssl.KeyManagerFactory;
-import javax.net.ssl.SSLContext;
-import javax.net.ssl.SSLSession;
-import javax.net.ssl.TrustManagerFactory;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.MultivaluedMap;
-import javax.ws.rs.core.Response;
-
-import com.gluster.storage.management.client.utils.ClientUtil;
-import com.gluster.storage.management.core.exceptions.GlusterRuntimeException;
-import com.sun.jersey.api.client.Client;
-import com.sun.jersey.api.client.ClientResponse;
-import com.sun.jersey.api.client.UniformInterfaceException;
-import com.sun.jersey.api.client.WebResource;
-import com.sun.jersey.api.client.WebResource.Builder;
-import com.sun.jersey.api.client.config.DefaultClientConfig;
-import com.sun.jersey.api.representation.Form;
-import com.sun.jersey.client.urlconnection.HTTPSProperties;
-import com.sun.jersey.core.util.MultivaluedMapImpl;
-import com.sun.jersey.multipart.FormDataMultiPart;
-
-public abstract class AbstractClient {
- private static final String HTTP_HEADER_AUTH = "Authorization";
- protected static final MultivaluedMap<String, String> NO_PARAMS = new MultivaluedMapImpl();
- protected static String clusterName;
- protected static String securityToken;
- protected WebResource resource;
- private String authHeader;
- private Client client;
-
- /**
- * This constructor will work only after the data model manager has been initialized.
- */
- public AbstractClient() {
- this(securityToken, clusterName);
- }
-
- /**
- * This constructor will work only after the data model manager has been initialized.
- */
- public AbstractClient(String clusterName) {
- this(securityToken, clusterName);
- }
-
- public AbstractClient(String securityToken, String clusterName) {
- AbstractClient.clusterName = clusterName;
- setSecurityToken(securityToken);
-
- createClient();
-
- // this must be after setting clusterName as sub-classes may refer to cluster name in the getResourcePath method
- resource = client.resource(ClientUtil.getServerBaseURI()).path(getResourcePath());
- }
-
- private void createClient() {
- SSLContext context = initializeSSLContext();
- DefaultClientConfig config = createClientConfig(context);
- client = Client.create(config);
- }
-
- private DefaultClientConfig createClientConfig(SSLContext context) {
- DefaultClientConfig config = new DefaultClientConfig();
- config.getProperties().put(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES,
- new HTTPSProperties(createHostnameVerifier(), context));
- return config;
- }
-
- private HostnameVerifier createHostnameVerifier() {
- HostnameVerifier hostnameVerifier = new HostnameVerifier() {
- @Override
- public boolean verify(String arg0, SSLSession arg1) {
- return true;
- }
- };
- return hostnameVerifier;
- }
-
- private SSLContext initializeSSLContext() {
- SSLContext context = null;
- try {
- context = SSLContext.getInstance(PROTOCOL_TLS);
-
- KeyStore keyStore = KeyStore.getInstance(KEYSTORE_TYPE_JKS);
- keyStore.load(loadResource(TRUSTED_KEYSTORE), TRUSTED_KEYSTORE_ACCESS.toCharArray());
-
- KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(ALGORITHM_SUNX509);
- keyManagerFactory.init(keyStore, TRUSTED_KEYSTORE_ACCESS.toCharArray());
-
- TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(ALGORITHM_SUNX509);
- trustManagerFactory.init(keyStore);
-
- context.init(keyManagerFactory.getKeyManagers(), trustManagerFactory.getTrustManagers(), null);
- } catch (Exception e) {
- throw new GlusterRuntimeException(
- "Couldn't initialize SSL Context with Gluster Management Gateway! Error: " + e, e);
- }
- return context;
- }
-
- private InputStream loadResource(String resourcePath) {
- return this.getClass().getClassLoader().getResourceAsStream(resourcePath);
- }
-
- /**
- * Fetches the given resource by dispatching a GET request
- *
- * @param res
- * Resource to be fetched
- * @param queryParams
- * Query parameters to be sent for the GET request
- * @param responseClass
- * Expected class of the response
- * @return Object of responseClass received as a result of the GET request
- */
- private <T> T fetchResource(WebResource res, MultivaluedMap<String, String> queryParams, Class<T> responseClass) {
- try {
- return res.queryParams(queryParams).header(HTTP_HEADER_AUTH, authHeader).accept(MediaType.APPLICATION_XML)
- .get(responseClass);
- } catch (Exception e1) {
- throw createGlusterException(e1);
- }
- }
-
- private GlusterRuntimeException createGlusterException(Exception e) {
- if (e instanceof GlusterRuntimeException) {
- return (GlusterRuntimeException) e;
- }
-
- if (e instanceof UniformInterfaceException) {
- UniformInterfaceException uie = (UniformInterfaceException) e;
- if ((uie.getResponse().getStatus() == Response.Status.UNAUTHORIZED.getStatusCode())) {
- // authentication failed. clear security token.
- setSecurityToken(null);
- return new GlusterRuntimeException("Invalid credentials!");
- } else {
- return new GlusterRuntimeException("[" + uie.getResponse().getStatus() + "]["
- + uie.getResponse().getEntity(String.class) + "]");
- }
- } else {
- Throwable cause = e.getCause();
- if (cause != null && cause instanceof ConnectException) {
- return new GlusterRuntimeException("Couldn't connect to Gluster Management Gateway!");
- }
-
- return new GlusterRuntimeException("Exception in REST communication! [" + e.getMessage() + "]", e);
- }
- }
-
- protected void downloadResource(WebResource res, String filePath) {
- ClientResponse response = null;
- try {
- response = res.header(HTTP_HEADER_AUTH, authHeader).accept(MediaType.APPLICATION_OCTET_STREAM)
- .get(ClientResponse.class);
- checkResponseStatus(response);
- } catch (Exception e1) {
- throw createGlusterException(e1);
- }
-
- try {
- if (!response.hasEntity()) {
- throw new GlusterRuntimeException("No entity in response!");
- }
-
- InputStream inputStream = response.getEntityInputStream();
- FileOutputStream outputStream = new FileOutputStream(filePath);
-
- int c;
- while ((c = inputStream.read()) != -1) {
- outputStream.write(c);
- }
- inputStream.close();
- outputStream.close();
- } catch (IOException e) {
- throw new GlusterRuntimeException("Error while downloading resource [" + res.getURI().getPath() + "]", e);
- }
- }
-
- public void uploadResource(WebResource res, FormDataMultiPart form) {
- try {
- res.header(HTTP_HEADER_AUTH, authHeader).type(MediaType.MULTIPART_FORM_DATA_TYPE).post(String.class, form);
- } catch (Exception e) {
- throw createGlusterException(e);
- }
- }
-
- /**
- * Fetches the default resource (the one returned by {@link AbstractClient#getResourcePath()}) by dispatching a GET
- * request on the resource
- *
- * @param queryParams
- * Query parameters to be sent for the GET request
- * @param responseClass
- * Expected class of the response
- * @return Object of responseClass received as a result of the GET request
- */
- protected <T> T fetchResource(MultivaluedMap<String, String> queryParams, Class<T> responseClass) {
- return fetchResource(resource, queryParams, responseClass);
- }
-
- /**
- * Fetches the default resource (the one returned by {@link AbstractClient#getResourcePath()}) by dispatching a GET
- * request on the resource
- *
- * @param responseClass
- * Expected class of the response
- * @return Object of responseClass received as a result of the GET request
- */
- protected <T> T fetchResource(Class<T> responseClass) {
- return fetchResource(resource, NO_PARAMS, responseClass);
- }
-
- /**
- * Fetches the resource whose name is arrived at by appending the "subResourceName" parameter to the default
- * resource (the one returned by {@link AbstractClient#getResourcePath()})
- *
- * @param subResourceName
- * Name of the sub-resource
- * @param responseClass
- * Expected class of the response
- * @return Object of responseClass received as a result of the GET request on the sub-resource
- */
- protected <T> T fetchSubResource(String subResourceName, Class<T> responseClass) {
- return fetchResource(resource.path(subResourceName), NO_PARAMS, responseClass);
- }
-
- protected void downloadSubResource(String subResourceName, String filePath) {
- downloadResource(resource.path(subResourceName), filePath);
- }
-
- /**
- * Fetches the resource whose name is arrived at by appending the "subResourceName" parameter to the default
- * resource (the one returned by {@link AbstractClient#getResourcePath()})
- *
- * @param subResourceName
- * Name of the sub-resource
- * @param queryParams
- * Query parameters to be sent for the GET request
- * @param responseClass
- * Expected class of the response
- * @return Object of responseClass received as a result of the GET request on the sub-resource
- */
- protected <T> T fetchSubResource(String subResourceName, MultivaluedMap<String, String> queryParams,
- Class<T> responseClass) {
- return fetchResource(resource.path(subResourceName), queryParams, responseClass);
- }
-
- private ClientResponse postRequest(WebResource resource, Form form) {
- try {
- ClientResponse response = prepareFormRequestBuilder(resource).post(ClientResponse.class, form);
- checkResponseStatus(response);
- return response;
- } catch (UniformInterfaceException e) {
- throw new GlusterRuntimeException(e.getResponse().getEntity(String.class));
- }
- }
-
- /**
- * Submits given object to the resource and returns the object received as response
- *
- * @param responseClass
- * Class of the object expected as response
- * @param requestObject
- * the Object to be submitted
- * @return Object of given class received as response
- */
- protected <T> T postObject(Class<T> responseClass, Object requestObject) {
- return resource.type(MediaType.APPLICATION_XML).header(HTTP_HEADER_AUTH, authHeader)
- .accept(MediaType.APPLICATION_XML).post(responseClass, requestObject);
- }
-
- /**
- * Submits given Form using POST method to the resource and returns the object received as response
- *
- * @param form
- * Form to be submitted
- */
- protected URI postRequest(Form form) {
- return postRequest(resource, form).getLocation();
- }
-
- /**
- * Submits given Form using POST method to the given sub-resource and returns the object received as response
- *
- * @param subResourceName
- * Name of the sub-resource to which the request is to be posted
- * @param form
- * Form to be submitted
- */
- protected void postRequest(String subResourceName, Form form) {
- postRequest(resource.path(subResourceName), form);
- }
-
- private ClientResponse putRequest(WebResource resource, Form form) {
- try {
- ClientResponse response = prepareFormRequestBuilder(resource).put(ClientResponse.class, form);
- checkResponseStatus(response);
- return response;
- } catch (Exception e) {
- throw createGlusterException(e);
- }
- }
-
- private void checkResponseStatus(ClientResponse response) {
- if ((response.getStatus() == Response.Status.UNAUTHORIZED.getStatusCode())) {
- // authentication failed. clear security token.
- setSecurityToken(null);
- throw new GlusterRuntimeException("Invalid credentials!");
- }
- if (response.getStatus() >= 300) {
- throw new GlusterRuntimeException(response.getEntity(String.class));
- }
- }
-
- public Builder prepareFormRequestBuilder(WebResource resource) {
- return resource.type(MediaType.APPLICATION_FORM_URLENCODED_TYPE).header(HTTP_HEADER_AUTH, authHeader)
- .accept(MediaType.APPLICATION_XML);
- }
-
- /**
- * Submits given Form using PUT method to the given sub-resource and returns the object received as response
- *
- * @param subResourceName
- * Name of the sub-resource to which the request is to be posted
- * @param form
- * Form to be submitted
- */
- protected void putRequest(String subResourceName, Form form) {
- putRequest(resource.path(subResourceName), form);
- }
-
- protected URI putRequestURI(String subResourceName, Form form) {
- ClientResponse response = putRequest(resource.path(subResourceName), form);
- return response.getLocation();
- }
-
- /**
- * Submits given Form using PUT method to the given sub-resource and returns the object received as response
- *
- * @param form
- * Form to be submitted
- */
- protected void putRequest(Form form) {
- putRequest(resource, form);
- }
-
- /**
- * Submits given Form using PUT method to the given sub-resource and returns the object received as response
- *
- * @param subResourceName
- * Name of the sub-resource to which the request is to be posted
- */
- protected void putRequest(String subResourceName) {
- try {
- prepareFormRequestBuilder(resource.path(subResourceName)).put();
- } catch (UniformInterfaceException e) {
- throw new GlusterRuntimeException(e.getResponse().getEntity(String.class));
- }
- }
-
- private void deleteResource(WebResource resource, MultivaluedMap<String, String> queryParams) {
- try {
- resource.queryParams(queryParams).header(HTTP_HEADER_AUTH, authHeader).delete();
- } catch (UniformInterfaceException e) {
- throw new GlusterRuntimeException(e.getResponse().getEntity(String.class));
- }
- }
-
- protected void deleteResource(MultivaluedMap<String, String> queryParams) {
- deleteResource(resource, queryParams);
- }
-
- protected void deleteSubResource(String subResourceName, MultivaluedMap<String, String> queryParams) {
- deleteResource(resource.path(subResourceName), queryParams);
- }
-
- protected void deleteSubResource(String subResourceName) {
- try {
- resource.path(subResourceName).header(HTTP_HEADER_AUTH, authHeader).delete();
- } catch (UniformInterfaceException e) {
- throw new GlusterRuntimeException(e.getResponse().getEntity(String.class));
- }
- }
-
- public abstract String getResourcePath();
-
- /**
- * @return the securityToken
- */
- protected String getSecurityToken() {
- return securityToken;
- }
-
- /**
- * @param securityToken
- * the securityToken to set
- */
- protected void setSecurityToken(String securityToken) {
- AbstractClient.securityToken = securityToken;
- authHeader = "Basic " + securityToken;
- }
-
- /**
- * @param uri
- * The URI to be fetched using GET API
- * @param responseClass
- * Expected type of response object
- * @return Object of the given class
- */
- protected <T> T fetchResource(URI uri, Class<T> responseClass) {
- return fetchResource(client.resource(uri), NO_PARAMS, responseClass);
- }
-}
diff --git a/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/ClustersClient.java b/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/ClustersClient.java deleted file mode 100644 index d6bf962a..00000000 --- a/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/ClustersClient.java +++ /dev/null @@ -1,72 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 Gluster, Inc. <http://www.gluster.com> - * This file is part of Gluster Management Console. - * - * Gluster Management Console is free software; you can redistribute it and/or - * modify it under the terms of the GNU Affero General Public License as published - * by the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * Gluster Management Console is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License - * for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see - * <http://www.gnu.org/licenses/>. - *******************************************************************************/ -package com.gluster.storage.management.client; - -import static com.gluster.storage.management.core.constants.RESTConstants.FORM_PARAM_CLUSTER_NAME; -import static com.gluster.storage.management.core.constants.RESTConstants.FORM_PARAM_SERVER_NAME; -import static com.gluster.storage.management.core.constants.RESTConstants.RESOURCE_PATH_CLUSTERS; - -import java.util.List; - -import com.gluster.storage.management.core.response.ClusterNameListResponse; -import com.sun.jersey.api.representation.Form; - -/** - * - */ -public class ClustersClient extends AbstractClient { - public ClustersClient() { - super(); - } - - public ClustersClient(String securityToken) { - super(); - setSecurityToken(securityToken); - } - - /* (non-Javadoc) - * @see com.gluster.storage.management.client.AbstractClient#getResourcePath() - */ - @Override - public String getResourcePath() { - return RESOURCE_PATH_CLUSTERS; - } - - public List<String> getClusterNames() { - return ((ClusterNameListResponse)fetchResource(ClusterNameListResponse.class)).getClusterNames(); - } - - public void createCluster(String clusterName) { - Form form = new Form(); - form.add(FORM_PARAM_CLUSTER_NAME, clusterName); - - postRequest(form); - } - - public void registerCluster(String clusterName, String knownServer) { - Form form = new Form(); - form.add(FORM_PARAM_CLUSTER_NAME, clusterName); - form.add(FORM_PARAM_SERVER_NAME, knownServer); - putRequest(form); - } - - public void deleteCluster(String clusterName) { - deleteSubResource(clusterName); - } -} diff --git a/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/DiscoveredServersClient.java b/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/DiscoveredServersClient.java deleted file mode 100644 index 6b7af5b0..00000000 --- a/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/DiscoveredServersClient.java +++ /dev/null @@ -1,87 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 Gluster, Inc. <http://www.gluster.com> - * This file is part of Gluster Management Console. - * - * Gluster Management Console is free software; you can redistribute it and/or - * modify it under the terms of the GNU Affero General Public License as published - * by the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * Gluster Management Console is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License - * for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see - * <http://www.gnu.org/licenses/>. - *******************************************************************************/ -package com.gluster.storage.management.client; - -import static com.gluster.storage.management.core.constants.RESTConstants.QUERY_PARAM_DETAILS; -import static com.gluster.storage.management.core.constants.RESTConstants.RESOURCE_PATH_DISCOVERED_SERVERS; - -import java.util.List; - -import javax.ws.rs.core.MultivaluedMap; - -import com.gluster.storage.management.core.model.Server; -import com.gluster.storage.management.core.response.ServerListResponse; -import com.gluster.storage.management.core.response.ServerNameListResponse; -import com.gluster.storage.management.core.utils.GlusterCoreUtil; -import com.sun.jersey.core.util.MultivaluedMapImpl; - -public class DiscoveredServersClient extends AbstractClient { - - public DiscoveredServersClient(String clusterName) { - super(clusterName); - } - - public DiscoveredServersClient(String securityToken, String clusterName) { - super(securityToken, clusterName); - } - - @Override - public String getResourcePath() { - return RESOURCE_PATH_DISCOVERED_SERVERS; - } - - private <T> T getDiscoveredServers(Boolean details, Class<T> responseClass) { - MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl(); - queryParams.putSingle(QUERY_PARAM_DETAILS, details.toString()); - return fetchResource(queryParams, responseClass); - } - - public List<String> getDiscoveredServerNames() { - return ((ServerNameListResponse) getDiscoveredServers(Boolean.FALSE, ServerNameListResponse.class)) - .getServerNames(); - } - - public List<Server> getDiscoveredServerDetails() { - List<Server> servers = ((ServerListResponse) getDiscoveredServers(Boolean.TRUE, ServerListResponse.class)) - .getServers(); - - for (Server server : servers) { - GlusterCoreUtil.updateServerNameOnDevices(server); - } - return servers; - } - - public Server getServer(String serverName) { - return (Server) fetchSubResource(serverName, Server.class); - } - - public static void main(String[] args) { - UsersClient usersClient = new UsersClient(); - try { - usersClient.authenticate("gluster", "gluster"); - DiscoveredServersClient serverResource = new DiscoveredServersClient(usersClient.getSecurityToken(), "new"); - List<String> discoveredServerNames = serverResource.getDiscoveredServerNames(); - System.out.println(discoveredServerNames); - List<Server> discoveredServers = serverResource.getDiscoveredServerDetails(); - System.out.println(discoveredServers); - } catch(Exception e) { - e.printStackTrace(); - } - } -} diff --git a/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/GlusterServersClient.java b/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/GlusterServersClient.java deleted file mode 100644 index 5fefedc0..00000000 --- a/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/GlusterServersClient.java +++ /dev/null @@ -1,139 +0,0 @@ -/******************************************************************************* -* Copyright (c) 2011 Gluster, Inc. <http://www.gluster.com> - * This file is part of Gluster Management Console. - * - * Gluster Management Console is free software; you can redistribute it and/or - * modify it under the terms of the GNU Affero General Public License as published - * by the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * Gluster Management Console is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License - * for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see - * <http://www.gnu.org/licenses/>. - *******************************************************************************/ -package com.gluster.storage.management.client; - -import static com.gluster.storage.management.core.constants.RESTConstants.QUERY_PARAM_DETAILS; -import static com.gluster.storage.management.core.constants.RESTConstants.RESOURCE_PATH_CLUSTERS; -import static com.gluster.storage.management.core.constants.RESTConstants.RESOURCE_SERVERS; - -import java.net.URI; -import java.util.List; - -import javax.ws.rs.core.MultivaluedMap; - -import com.gluster.storage.management.core.constants.RESTConstants; -import com.gluster.storage.management.core.model.GlusterServer; -import com.gluster.storage.management.core.model.ServerStats; -import com.gluster.storage.management.core.response.FsTypeListResponse; -import com.gluster.storage.management.core.response.GlusterServerListResponse; -import com.gluster.storage.management.core.response.StringListResponse; -import com.gluster.storage.management.core.utils.GlusterCoreUtil; -import com.sun.jersey.api.representation.Form; -import com.sun.jersey.core.util.MultivaluedMapImpl; - -public class GlusterServersClient extends AbstractClient { - - public GlusterServersClient() { - super(); - } - - public GlusterServersClient(String clusterName) { - super(clusterName); - } - - public GlusterServersClient(String securityToken, String clusterName) { - super(securityToken, clusterName); - } - - @Override - public String getResourcePath() { - return RESOURCE_PATH_CLUSTERS + "/" + clusterName + "/" + RESOURCE_SERVERS; - } - - public List<GlusterServer> getServers() { - MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl(); - queryParams.putSingle(QUERY_PARAM_DETAILS, "true"); - List<GlusterServer> servers = ((GlusterServerListResponse) fetchResource(queryParams, GlusterServerListResponse.class)).getServers(); - for(GlusterServer server : servers) { - GlusterCoreUtil.updateServerNameOnDevices(server); - } - return servers; - } - - public GlusterServer getGlusterServer(String serverName) { - GlusterServer server = (GlusterServer) fetchSubResource(serverName, GlusterServer.class); - GlusterCoreUtil.updateServerNameOnDevices(server); - return server; - } - - public URI addServer(String serverName) { - Form form = new Form(); - form.add(RESTConstants.FORM_PARAM_SERVER_NAME, serverName); - return postRequest(form); - } - - public List<String> getFSTypes(String serverName) { - FsTypeListResponse fsTypeListResponse = ((FsTypeListResponse) fetchSubResource(serverName + "/" + RESTConstants.RESOURCE_FSTYPES, - FsTypeListResponse.class)); - return fsTypeListResponse.getFsTypes(); - } - - public URI initializeDisk(String serverName, String diskName, String fsType, String mountPoint) { - Form form = new Form(); - form.add(RESTConstants.FORM_PARAM_FSTYPE, fsType); - form.add(RESTConstants.FORM_PARAM_MOUNTPOINT, fsType); - return putRequestURI(serverName + "/" + RESTConstants.RESOURCE_DISKS + "/" + diskName, form); - } - - public void removeServer(String serverName) { - deleteSubResource(serverName); - } - - public ServerStats getCpuStats(String serverName, String period) { - MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl(); - queryParams.add(RESTConstants.QUERY_PARAM_TYPE, RESTConstants.STATISTICS_TYPE_CPU); - queryParams.add(RESTConstants.QUERY_PARAM_PERIOD, period); - return fetchSubResource(serverName + "/" + RESTConstants.RESOURCE_STATISTICS, queryParams, ServerStats.class); - } - - public ServerStats getMemoryStats(String serverName, String period) { - MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl(); - queryParams.add(RESTConstants.QUERY_PARAM_TYPE, RESTConstants.STATISTICS_TYPE_MEMORY); - queryParams.add(RESTConstants.QUERY_PARAM_PERIOD, period); - return fetchSubResource(serverName + "/" + RESTConstants.RESOURCE_STATISTICS, queryParams, ServerStats.class); - } - - public ServerStats getNetworkStats(String serverName, String networkInterface, String period) { - MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl(); - queryParams.add(RESTConstants.QUERY_PARAM_TYPE, RESTConstants.STATISTICS_TYPE_NETWORK); - queryParams.add(RESTConstants.QUERY_PARAM_PERIOD, period); - queryParams.add(RESTConstants.QUERY_PARAM_INTERFACE, networkInterface); - return fetchSubResource(serverName + "/" + RESTConstants.RESOURCE_STATISTICS, queryParams, ServerStats.class); - } - - public ServerStats getAggregatedCpuStats(String period) { - MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl(); - queryParams.add(RESTConstants.QUERY_PARAM_TYPE, RESTConstants.STATISTICS_TYPE_CPU); - queryParams.add(RESTConstants.QUERY_PARAM_PERIOD, period); - return fetchSubResource(RESTConstants.RESOURCE_STATISTICS, queryParams, ServerStats.class); - } - - public ServerStats getAggregatedNetworkStats(String period) { - MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl(); - queryParams.add(RESTConstants.QUERY_PARAM_TYPE, RESTConstants.STATISTICS_TYPE_NETWORK); - queryParams.add(RESTConstants.QUERY_PARAM_PERIOD, period); - return fetchSubResource(RESTConstants.RESOURCE_STATISTICS, queryParams, ServerStats.class); - } - - public GlusterServer getGlusterServer(URI uri) { - GlusterServer server = fetchResource(uri, GlusterServer.class); - GlusterCoreUtil.updateServerNameOnDevices(server); - return server; - } -} diff --git a/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/KeysClient.java b/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/KeysClient.java deleted file mode 100644 index 51fda466..00000000 --- a/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/KeysClient.java +++ /dev/null @@ -1,55 +0,0 @@ -/** - * KeysClient.java - * - * Copyright (c) 2011 Gluster, Inc. <http://www.gluster.com> - * This file is part of Gluster Management Console. - * - * Gluster Management Console is free software; you can redistribute it and/or - * modify it under the terms of the GNU Affero General Public License as published - * by the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * Gluster Management Console is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License - * for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see - * <http://www.gnu.org/licenses/>. - */ -package com.gluster.storage.management.client; - -import java.io.FileInputStream; -import java.io.FileNotFoundException; - -import javax.ws.rs.core.MediaType; - -import com.gluster.storage.management.core.constants.RESTConstants; -import com.sun.jersey.multipart.FormDataMultiPart; - -public class KeysClient extends AbstractClient { - - public KeysClient() { - super(); - } - - @Override - public String getResourcePath() { - return RESTConstants.RESOURCE_KEYS; - } - - public void exportSshKeys(String filePath) { - downloadResource(resource, filePath); - } - - public void importSshKeys(String keysFile) { - FormDataMultiPart form = new FormDataMultiPart(); - try { - form.field("file", new FileInputStream(keysFile), MediaType.TEXT_PLAIN_TYPE); - } catch (FileNotFoundException e) { - e.printStackTrace(); - } - uploadResource(resource, form); - } -} diff --git a/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/TasksClient.java b/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/TasksClient.java deleted file mode 100644 index 46077371..00000000 --- a/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/TasksClient.java +++ /dev/null @@ -1,103 +0,0 @@ -/** - * tasksClient.java - * - * Copyright (c) 2011 Gluster, Inc. <http://www.gluster.com> - * This file is part of Gluster Management Console. - * - * Gluster Management Console is free software; you can redistribute it and/or - * modify it under the terms of the GNU Affero General Public License as published - * by the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * Gluster Management Console is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License - * for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see - * <http://www.gnu.org/licenses/>. - */ -package com.gluster.storage.management.client; - -import java.net.URI; -import java.util.List; - -import javax.ws.rs.core.MultivaluedMap; - -import com.gluster.storage.management.core.constants.RESTConstants; -import com.gluster.storage.management.core.model.TaskInfo; -import com.gluster.storage.management.core.response.TaskInfoListResponse; -import com.sun.jersey.api.representation.Form; -import com.sun.jersey.core.util.MultivaluedMapImpl; - -public class TasksClient extends AbstractClient { - - public TasksClient() { - super(); - } - - public TasksClient(String clusterName) { - super(clusterName); - } - - public TasksClient(String securityToken,String clusterName) { - super(securityToken, clusterName); - } - - @Override - public String getResourcePath() { - return RESTConstants.RESOURCE_PATH_CLUSTERS + "/" + clusterName + "/" + RESTConstants.RESOURCE_TASKS + "/"; - } - - public List<TaskInfo> getAllTasks() { // TaskListResponse get only the list of taskInfo not list of Tasks - return ((TaskInfoListResponse) fetchResource(TaskInfoListResponse.class)).getTaskList(); - } - - // see startMigration @ VolumesClient, etc - public void pauseTask(String taskId) { - Form form = new Form(); - form.add(RESTConstants.FORM_PARAM_OPERATION, RESTConstants.TASK_PAUSE); - - putRequest( taskId, form); - } - - public void resumeTask(String taskId) { - Form form = new Form(); - form.add(RESTConstants.FORM_PARAM_OPERATION, RESTConstants.TASK_RESUME); - - putRequest(taskId, form); - } - - public void stopTask(String taskId) { - Form form = new Form(); - form.add(RESTConstants.FORM_PARAM_OPERATION, RESTConstants.TASK_STOP); - - putRequest(taskId, form); - } - - public void commitTask(String taskId) { - Form form = new Form(); - form.add(RESTConstants.FORM_PARAM_OPERATION, RESTConstants.TASK_COMMIT); - - putRequest(taskId, form); - } - - public void getTaskStatus(String taskId) { - Form form = new Form(); - form.add(RESTConstants.FORM_PARAM_OPERATION, RESTConstants.TASK_STATUS); - - putRequest(taskId, form); - } - - public void deleteTask(String taskId) { - MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl(); - queryParams.add(RESTConstants.FORM_PARAM_OPERATION, RESTConstants.TASK_DELETE); - - deleteSubResource(taskId, queryParams); - } - - public TaskInfo getTaskInfo(URI uri) { - return ((TaskInfo) fetchResource(uri, TaskInfo.class)); - } -} diff --git a/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/UsersClient.java b/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/UsersClient.java deleted file mode 100644 index 4e89e994..00000000 --- a/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/UsersClient.java +++ /dev/null @@ -1,96 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 Gluster, Inc. <http://www.gluster.com> - * This file is part of Gluster Management Console. - * - * Gluster Management Console is free software; you can redistribute it and/or - * modify it under the terms of the GNU Affero General Public License as published - * by the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * Gluster Management Console is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License - * for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see - * <http://www.gnu.org/licenses/>. - *******************************************************************************/ -package com.gluster.storage.management.client; - -import static com.gluster.storage.management.core.constants.RESTConstants.FORM_PARAM_NEW_PASSWORD; -import static com.gluster.storage.management.core.constants.RESTConstants.FORM_PARAM_OLD_PASSWORD; - -import com.gluster.storage.management.core.constants.RESTConstants; -import com.gluster.storage.management.core.exceptions.GlusterRuntimeException; -import com.gluster.storage.management.core.model.Status; -import com.sun.jersey.api.representation.Form; -import com.sun.jersey.core.util.Base64; - - -public class UsersClient extends AbstractClient { - private String generateSecurityToken(String user, String password) { - return new String(Base64.encode(user + ":" + password)); - } - - public UsersClient() { - super(); - } - - public void authenticate(String user, String password) { - setSecurityToken(generateSecurityToken(user, password)); - fetchSubResource(user, Status.class); - } - - public void changePassword(String user, String oldPassword, String newPassword) { - String oldSecurityToken = getSecurityToken(); - String newSecurityToken = generateSecurityToken(user, oldPassword); - if(!oldSecurityToken.equals(newSecurityToken)) { - throw new GlusterRuntimeException("Invalid old password!"); - } - - Form form = new Form(); - form.add(FORM_PARAM_OLD_PASSWORD, oldPassword); - form.add(FORM_PARAM_NEW_PASSWORD, newPassword); - putRequest(user, form); - - // password changed. set the new security token - setSecurityToken(generateSecurityToken(user, newPassword)); - //authenticate(user, newPassword); - } - - public static void main(String[] args) { - UsersClient authClient = new UsersClient(); - - // authenticate user - authClient.authenticate("gluster", "gluster"); - - // change password to gluster1 - authClient.changePassword("gluster", "gluster", "gluster1"); - - // change it back to gluster - authClient.changePassword("gluster", "gluster1", "gluster"); - - System.out.println("success"); - } - - /* - * (non-Javadoc) - * - * @see com.gluster.storage.management.client.AbstractClient#getResourceName() - */ - @Override - public String getResourcePath() { - return RESTConstants.RESOURCE_USERS; - } - - /* - * (non-Javadoc) - * - * @see com.gluster.storage.management.client.AbstractClient#getSecurityToken() - */ - @Override - public String getSecurityToken() { - return super.getSecurityToken(); - } -} diff --git a/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/VolumesClient.java b/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/VolumesClient.java deleted file mode 100644 index ec8d0212..00000000 --- a/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/VolumesClient.java +++ /dev/null @@ -1,281 +0,0 @@ -/** - * VolumesClient.java - * - * Copyright (c) 2011 Gluster, Inc. <http://www.gluster.com> - * This file is part of Gluster Management Console. - * - * Gluster Management Console is free software; you can redistribute it and/or - * modify it under the terms of the GNU Affero General Public License as published - * by the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * Gluster Management Console is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License - * for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see - * <http://www.gnu.org/licenses/>. - */ -package com.gluster.storage.management.client; - -import static com.gluster.storage.management.core.constants.RESTConstants.FORM_PARAM_ACCESS_PROTOCOLS; -import static com.gluster.storage.management.core.constants.RESTConstants.FORM_PARAM_BRICKS; -import static com.gluster.storage.management.core.constants.RESTConstants.FORM_PARAM_CIFS_USERS; -import static com.gluster.storage.management.core.constants.RESTConstants.FORM_PARAM_REPLICA_COUNT; -import static com.gluster.storage.management.core.constants.RESTConstants.FORM_PARAM_STRIPE_COUNT; -import static com.gluster.storage.management.core.constants.RESTConstants.FORM_PARAM_TRANSPORT_TYPE; -import static com.gluster.storage.management.core.constants.RESTConstants.FORM_PARAM_VOLUME_NAME; -import static com.gluster.storage.management.core.constants.RESTConstants.FORM_PARAM_VOLUME_OPTIONS; -import static com.gluster.storage.management.core.constants.RESTConstants.FORM_PARAM_VOLUME_TYPE; - -import java.net.URI; -import java.util.Date; -import java.util.List; -import java.util.Set; - -import javax.ws.rs.core.MultivaluedMap; - -import com.gluster.storage.management.core.constants.CoreConstants; -import com.gluster.storage.management.core.constants.GlusterConstants; -import com.gluster.storage.management.core.constants.RESTConstants; -import com.gluster.storage.management.core.model.Brick; -import com.gluster.storage.management.core.model.Volume; -import com.gluster.storage.management.core.model.VolumeLogMessage; -import com.gluster.storage.management.core.model.VolumeOptionInfo; -import com.gluster.storage.management.core.response.LogMessageListResponse; -import com.gluster.storage.management.core.response.VolumeListResponse; -import com.gluster.storage.management.core.response.VolumeOptionInfoListResponse; -import com.gluster.storage.management.core.utils.DateUtil; -import com.gluster.storage.management.core.utils.GlusterCoreUtil; -import com.gluster.storage.management.core.utils.StringUtil; -import com.sun.jersey.api.representation.Form; -import com.sun.jersey.core.util.MultivaluedMapImpl; - -public class VolumesClient extends AbstractClient { - public VolumesClient() { - super(); - } - - public VolumesClient(String clusterName) { - super(clusterName); - } - - public VolumesClient(String securityToken, String clusterName) { - super(securityToken, clusterName); - } - - @Override - public String getResourcePath() { - return RESTConstants.RESOURCE_PATH_CLUSTERS + "/" + clusterName + "/" + RESTConstants.RESOURCE_VOLUMES; - } - - public void createVolume(Volume volume) { - Form form = new Form(); - form.add(FORM_PARAM_VOLUME_NAME, volume.getName()); - form.add(FORM_PARAM_VOLUME_TYPE, volume.getVolumeType().toString()); - form.add(FORM_PARAM_TRANSPORT_TYPE, volume.getTransportType().toString()); - form.add(FORM_PARAM_REPLICA_COUNT, volume.getReplicaCount()); - form.add(FORM_PARAM_STRIPE_COUNT, volume.getStripeCount()); - form.add(FORM_PARAM_BRICKS, StringUtil.collectionToString(volume.getBricks(), ",")); - form.add(FORM_PARAM_ACCESS_PROTOCOLS, StringUtil.collectionToString(volume.getNASProtocols(), ",")); - form.add(FORM_PARAM_VOLUME_OPTIONS, StringUtil.collectionToString(volume.getOptions().getOptions(), ",")); - if (volume.isCifsEnable()) { - form.add(FORM_PARAM_CIFS_USERS, StringUtil.collectionToString(volume.getCifsUsers(), ",")); - } - postRequest(form); - } - - private void performOperation(String volumeName, String operation, Boolean force) { - Form form = new Form(); - form.add(RESTConstants.FORM_PARAM_OPERATION, operation); - form.add(RESTConstants.FORM_PARAM_FORCE, force); - - putRequest(volumeName, form); - } - - public void startVolume(String volumeName, Boolean forceStart) { - performOperation(volumeName, RESTConstants.TASK_START, forceStart); - } - - public void stopVolume(String volumeName, Boolean forceStop) { - performOperation(volumeName, RESTConstants.TASK_STOP, forceStop); - } - - public void setCifsConfig(String volumeName, Boolean isCifsEnabled, String cifsUsers) { - Form form = new Form(); - form.add(RESTConstants.FORM_PARAM_OPERATION, RESTConstants.FORM_PARAM_CIFS_CONFIG); - form.add(RESTConstants.FORM_PARAM_CIFS_ENABLE, isCifsEnabled); - form.add(RESTConstants.FORM_PARAM_CIFS_USERS, cifsUsers); - putRequest(volumeName, form); - } - - public boolean volumeExists(String volumeName) { - try { - // TODO: instead of fetching full volume name, fetch list of volumes and check if - // it contains our volume name - getVolume(volumeName); - return true; - } catch(Exception e) { - return false; - } - } - - public void setVolumeOption(String volume, String key, String value) { - Form form = new Form(); - form.add(RESTConstants.FORM_PARAM_OPTION_KEY, key); - form.add(RESTConstants.FORM_PARAM_OPTION_VALUE, value); - postRequest(volume + "/" + RESTConstants.RESOURCE_OPTIONS, form); - } - - public void resetVolumeOptions(String volume) { - putRequest(volume + "/" + RESTConstants.RESOURCE_OPTIONS); - } - - public List<Volume> getAllVolumes() { - return ((VolumeListResponse) fetchResource(VolumeListResponse.class)).getVolumes(); - } - - public Volume getVolume(String volumeName) { - return (Volume)fetchSubResource(volumeName, Volume.class); - } - - public void deleteVolume(String volumeName, boolean deleteOption) { - MultivaluedMap<String, String> queryParams = prepareDeleteVolumeQueryParams(deleteOption); - deleteSubResource(volumeName, queryParams); - } - - public List<VolumeOptionInfo> getVolumeOptionsInfo() { - return ((VolumeOptionInfoListResponse) fetchSubResource(RESTConstants.RESOURCE_DEFAULT_OPTIONS, - VolumeOptionInfoListResponse.class)).getOptions(); - } - - public void addBricks(String volumeName, Set<String> brickList) { - String bricks = StringUtil.collectionToString(brickList, ","); - Form form = new Form(); - form.add(RESTConstants.FORM_PARAM_BRICKS, bricks); - postRequest(volumeName + "/" + RESTConstants.RESOURCE_BRICKS, form); - } - - /** - * Fetches volume logs for the given volume based on given filter criteria - * - * @param volumeName - * Name of volume whose logs are to be fetched - * @param brickName - * Name of the brick whose logs are to be fetched. Pass ALL to fetch log messages from all bricks of the - * volume. - * @param severity - * Log severity {@link GlusterConstants#VOLUME_LOG_LEVELS_ARR}. Pass ALL to fetch log messages of all - * severity levels. - * @param fromTimestamp - * From timestamp. Pass null if this filter is not required. - * @param toTimestamp - * To timestamp. Pass null if this filter is not required. - * @param messageCount - * Number of most recent log messages to be fetched (from each disk) - * @return Log Message List response received from the Gluster Management Server. - */ - public List<VolumeLogMessage> getLogs(String volumeName, String brickName, String severity, Date fromTimestamp, - Date toTimestamp, int messageCount) { - MultivaluedMap<String, String> queryParams = prepareGetLogQueryParams(brickName, severity, fromTimestamp, - toTimestamp, messageCount); - - return ((LogMessageListResponse) fetchSubResource(volumeName + "/" + RESTConstants.RESOURCE_LOGS, - queryParams, LogMessageListResponse.class)).getLogMessages(); - } - - public void downloadLogs(String volumeName, String filePath) { - downloadSubResource(volumeName + "/" + RESTConstants.RESOURCE_LOGS + "/" + RESTConstants.RESOURCE_DOWNLOAD, filePath); - } - - public void removeBricks(String volumeName, Set<Brick> BrickList, boolean deleteOption) { - String bricks = StringUtil.collectionToString(GlusterCoreUtil.getQualifiedBrickList(BrickList), ","); - MultivaluedMap<String, String> queryParams = prepareRemoveBrickQueryParams(volumeName, bricks, deleteOption); - deleteSubResource(volumeName + "/" + RESTConstants.RESOURCE_BRICKS, queryParams); - } - - private MultivaluedMap<String, String> prepareRemoveBrickQueryParams(String volumeName, String bricks, - boolean deleteOption) { - MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl(); - queryParams.add(RESTConstants.QUERY_PARAM_VOLUME_NAME, volumeName); - queryParams.add(RESTConstants.QUERY_PARAM_BRICKS, bricks); - queryParams.add(RESTConstants.QUERY_PARAM_DELETE_OPTION, "" + deleteOption); - return queryParams; - } - - private MultivaluedMap<String, String> prepareDeleteVolumeQueryParams(boolean deleteOption) { - MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl(); - queryParams.add(RESTConstants.QUERY_PARAM_DELETE_OPTION, "" + deleteOption); - return queryParams; - } - - private MultivaluedMap<String, String> prepareGetLogQueryParams(String brickName, String severity, - Date fromTimestamp, Date toTimestamp, int messageCount) { - MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl(); - queryParams.add(RESTConstants.QUERY_PARAM_LINE_COUNT, "" + messageCount); - if (!brickName.equals(CoreConstants.ALL)) { - queryParams.add(RESTConstants.QUERY_PARAM_BRICK_NAME, brickName); - } - - if (!severity.equals(CoreConstants.ALL)) { - queryParams.add(RESTConstants.QUERY_PARAM_LOG_SEVERITY, severity); - } - - if (fromTimestamp != null) { - queryParams.add(RESTConstants.QUERY_PARAM_FROM_TIMESTAMP, - DateUtil.dateToString(fromTimestamp, CoreConstants.DATE_WITH_TIME_FORMAT)); - } - - if (toTimestamp != null) { - queryParams.add(RESTConstants.QUERY_PARAM_TO_TIMESTAMP, - DateUtil.dateToString(toTimestamp, CoreConstants.DATE_WITH_TIME_FORMAT)); - } - return queryParams; - } - - public URI startMigration(String volumeName, String brickFrom, String brickTo, Boolean autoCommit) { - Form form = new Form(); - form.add(RESTConstants.FORM_PARAM_SOURCE, brickFrom); - form.add(RESTConstants.FORM_PARAM_TARGET, brickTo); - form.add(RESTConstants.FORM_PARAM_OPERATION, RESTConstants.TASK_START); - form.add(RESTConstants.FORM_PARAM_AUTO_COMMIT, autoCommit); - return putRequestURI(volumeName + "/" + RESTConstants.RESOURCE_BRICKS, form); - } - - public URI rebalanceStart(String volumeName, Boolean fixLayout, Boolean migrateData, Boolean forcedDataMigrate) { - Form form = new Form(); - form.add(RESTConstants.FORM_PARAM_OPERATION, RESTConstants.TASK_REBALANCE_START); - form.add(RESTConstants.FORM_PARAM_FIX_LAYOUT, fixLayout); - form.add(RESTConstants.FORM_PARAM_MIGRATE_DATA, migrateData); - form.add(RESTConstants.FORM_PARAM_FORCED_DATA_MIGRATE, forcedDataMigrate); - return putRequestURI(volumeName, form); - } - - public void rebalanceStop(String volumeName) { - Form form = new Form(); - form.add(RESTConstants.FORM_PARAM_OPERATION, RESTConstants.TASK_REBALANCE_STOP); - putRequest(volumeName, form); - } - - public void volumeLogRotate(String volumeName, List<String> brickList) { - Form form = new Form(); - String bricks = StringUtil.collectionToString(brickList, ","); - form.add(RESTConstants.FORM_PARAM_OPERATION, RESTConstants.TASK_LOG_ROTATE); - form.add(FORM_PARAM_BRICKS, bricks); - putRequest(volumeName, form); - } - - public static void main(String[] args) { - UsersClient usersClient = new UsersClient(); - try { - usersClient.authenticate("gluster", "gluster"); - VolumesClient client = new VolumesClient(usersClient.getSecurityToken()); - System.out.println(client.getAllVolumes()); -// client.downloadLogs("vol1", "/tmp/temp1.tar.gz"); - } catch(Exception e) { - e.printStackTrace(); - } - } -} diff --git a/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/constants/ClientConstants.java b/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/constants/ClientConstants.java deleted file mode 100644 index e253dfa5..00000000 --- a/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/constants/ClientConstants.java +++ /dev/null @@ -1,39 +0,0 @@ -/** - * ClientConstants.java - * - * Copyright (c) 2011 Gluster, Inc. <http://www.gluster.com> - * This file is part of Gluster Management Console. - * - * Gluster Management Console is free software; you can redistribute it and/or - * modify it under the terms of the GNU Affero General Public License as published - * by the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * Gluster Management Console is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License - * for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see - * <http://www.gnu.org/licenses/>. - */ -package com.gluster.storage.management.client.constants; - -/** - * - */ -public class ClientConstants { - public static final String SYS_PROP_SERVER_URL = "gluster.server.url"; - public static final String DEFAULT_SERVER_URL = "https://localhost:8443/glustermg/linux.gtk.x86_64"; - public static final String CONTEXT_ROOT = "glustermg"; - public static final String REST_API_VERSION = "1.0.0"; - - // SSL related - public static final String TRUSTED_KEYSTORE = "gmc-trusted.keystore"; - public static final String TRUSTED_KEYSTORE_ACCESS = "gluster"; - public static final String PROTOCOL_TLS = "TLS"; - public static final String ALGORITHM_SUNX509 = "SunX509"; - public static final String KEYSTORE_TYPE_JKS = "JKS"; -} - diff --git a/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/utils/ClientUtil.java b/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/utils/ClientUtil.java deleted file mode 100644 index 3f87fd27..00000000 --- a/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/utils/ClientUtil.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.gluster.storage.management.client.utils; - -import java.net.URI; - -import javax.ws.rs.core.UriBuilder; - -import com.gluster.storage.management.client.constants.ClientConstants; - -public class ClientUtil { - - public static URI getServerBaseURI() { - return UriBuilder.fromUri(getBaseURL()).path(ClientConstants.REST_API_VERSION).build(); - } - - private static String getBaseURL() { - // remove the platform path (e.g. /linux.gtk.x86_64) from the URL - return System.getProperty(ClientConstants.SYS_PROP_SERVER_URL, ClientConstants.DEFAULT_SERVER_URL) - .replaceAll(ClientConstants.CONTEXT_ROOT + "\\/.*", ClientConstants.CONTEXT_ROOT + "\\/"); - } -} |
