Repository: stratos Updated Branches: refs/heads/4.0.0-grouping 2dac52796 -> 448c13e31
adding the initial implemetation of meta data client Project: http://git-wip-us.apache.org/repos/asf/stratos/repo Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/448c13e3 Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/448c13e3 Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/448c13e3 Branch: refs/heads/4.0.0-grouping Commit: 448c13e31fedeadd9635a219ae2eeeafb125da1d Parents: 2dac527 Author: Isuru Haththotuwa <[email protected]> Authored: Fri Sep 19 14:21:51 2014 +0530 Committer: Isuru Haththotuwa <[email protected]> Committed: Fri Sep 19 14:21:51 2014 +0530 ---------------------------------------------------------------------- .../org.apache.stratos.metadata.client/pom.xml | 60 +++++++++++ .../client/DefaultMetaDataServiceClient.java | 80 +++++++++++++++ .../metadata/client/MetaDataServiceClient.java | 102 +++++++++++++++++++ .../client/MetaDataServiceClientManager.java | 93 +++++++++++++++++ .../client/data/extractor/DataExtractor.java | 34 +++++++ .../data/extractor/DefaultDataExtractor.java | 40 ++++++++ .../exception/DataExtractorException.java | 47 +++++++++ .../MetaDataServiceClientExeption.java | 48 +++++++++ .../client/exception/RestClientException.java | 48 +++++++++ .../metadata/client/pojo/DataContext.java | 58 +++++++++++ .../metadata/client/rest/DefaultRestClient.java | 85 ++++++++++++++++ .../metadata/client/rest/RestClient.java | 32 ++++++ components/pom.xml | 3 +- 13 files changed, 729 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/stratos/blob/448c13e3/components/org.apache.stratos.metadata.client/pom.xml ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.metadata.client/pom.xml b/components/org.apache.stratos.metadata.client/pom.xml new file mode 100644 index 0000000..9c6683c --- /dev/null +++ b/components/org.apache.stratos.metadata.client/pom.xml @@ -0,0 +1,60 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.apache.stratos</groupId> + <artifactId>stratos-components-parent</artifactId> + <version>4.1.0-SNAPSHOT</version> + </parent> + + <groupId>org.apache.stratos</groupId> + <artifactId>org.apache.stratos.metadata.client</artifactId> + <version>4.0.0-SNAPSHOT</version> + <packaging>bundle</packaging> + + <name>Apache Stratos - Metadata Client</name> + + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + </properties> + + <dependencies> + <dependency> + <groupId>org.apache.httpcomponents</groupId> + <artifactId>httpclient</artifactId> + <version>4.3.5</version> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-scr-plugin</artifactId> + </plugin> + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-bundle-plugin</artifactId> + + <extensions>true</extensions> + <configuration> + <instructions> + <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName> + <Bundle-Name>${project.artifactId}</Bundle-Name> + <Export-Package> + org.apache.stratos.metadata.client.*, + </Export-Package> + <Import-Package> + !org.apache.commons.logging, + org.apache.commons.logging; version=0.0.0, + *;resolution:=optional + </Import-Package> + <DynamicImport-Package>*</DynamicImport-Package> + </instructions> + </configuration> + </plugin> + </plugins> + </build> + +</project> http://git-wip-us.apache.org/repos/asf/stratos/blob/448c13e3/components/org.apache.stratos.metadata.client/src/main/java/org/apache/stratos/metadata/client/DefaultMetaDataServiceClient.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.metadata.client/src/main/java/org/apache/stratos/metadata/client/DefaultMetaDataServiceClient.java b/components/org.apache.stratos.metadata.client/src/main/java/org/apache/stratos/metadata/client/DefaultMetaDataServiceClient.java new file mode 100644 index 0000000..6f8e9cb --- /dev/null +++ b/components/org.apache.stratos.metadata.client/src/main/java/org/apache/stratos/metadata/client/DefaultMetaDataServiceClient.java @@ -0,0 +1,80 @@ +/* + * 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. + */ + +package org.apache.stratos.metadata.client; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.stratos.metadata.client.exception.MetaDataServiceClientExeption; +import org.apache.stratos.metadata.client.rest.DefaultRestClient; +import org.apache.stratos.metadata.client.rest.RestClient; + +import java.util.Map; +import java.util.Set; + + +public class DefaultMetaDataServiceClient implements MetaDataServiceClient { + + private static Log log = LogFactory.getLog(DefaultMetaDataServiceClient.class); + + private RestClient restClient; + private String baseUrl; + + public DefaultMetaDataServiceClient (String baseUrl) { + this.baseUrl = baseUrl; + restClient = new DefaultRestClient(); + } + + public void initialize() { + // initialization, if any + } + + public void addProperty(String appId, String clusterId, String propertyKey, String propertyValue) + throws MetaDataServiceClientExeption { + //To change body of implemented methods use File | Settings | File Templates. + } + +// public void addProperty(String appId, String propertyKey, String propertyValue) +// throws MetaDataServiceClientExeption { +// //To change body of implemented methods use File | Settings | File Templates. +// } + + public Map<String, Set<String>> getProperties(String appId, String clusterId) + throws MetaDataServiceClientExeption { + return null; //To change body of implemented methods use File | Settings | File Templates. + } + +// public Map<String, Set<String>> getProperties(String appId) throws MetaDataServiceClientExeption { +// return null; //To change body of implemented methods use File | Settings | File Templates. +// } + + public Set<String> getProperty(String appId, String propertyKey) throws MetaDataServiceClientExeption { + return null; //To change body of implemented methods use File | Settings | File Templates. + } + + public Set<String> getProperty(String appId, String clusterId, String propertyKey) + throws MetaDataServiceClientExeption { + return null; //To change body of implemented methods use File | Settings | File Templates. + } + + + public void terminate() throws MetaDataServiceClientExeption { + restClient = null; + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/448c13e3/components/org.apache.stratos.metadata.client/src/main/java/org/apache/stratos/metadata/client/MetaDataServiceClient.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.metadata.client/src/main/java/org/apache/stratos/metadata/client/MetaDataServiceClient.java b/components/org.apache.stratos.metadata.client/src/main/java/org/apache/stratos/metadata/client/MetaDataServiceClient.java new file mode 100644 index 0000000..ff26264 --- /dev/null +++ b/components/org.apache.stratos.metadata.client/src/main/java/org/apache/stratos/metadata/client/MetaDataServiceClient.java @@ -0,0 +1,102 @@ +/* + * 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. + */ + +package org.apache.stratos.metadata.client; + +import org.apache.stratos.metadata.client.exception.MetaDataServiceClientExeption; + +import java.util.Map; +import java.util.Set; + +public interface MetaDataServiceClient { + + /** + * Initialize the MetaDataServiceClient. Should be called once before using the MetaDataServiceClient. + * @throws MetaDataServiceClientExeption + */ + public void initialize (); + + /** + * Adds a property key value pair for the relevant cluster of the specified app + * + * @param appId Application id + * @param clusterId Cluster id + * @param propertyKey Key of the Property + * @param propertyValue Value of the Property + * @throws MetaDataServiceClientExeption + */ + public void addProperty (String appId, String clusterId, String propertyKey, String propertyValue) throws MetaDataServiceClientExeption; + +// /** +// * Adds a property key value pair for the specified app +// * +// * @param appId Application id +// * @param propertyKey Key of the Property +// * @param propertyValue Value of the Property +// * @throws MetaDataServiceClientExeption +// */ +// public void addProperty (String appId, String propertyKey, String propertyValue) throws MetaDataServiceClientExeption; +// +// /** +// * Retrieves the property key value pairs for the relevant cluster of the specified app +// * +// * @param appId Application id +// * @param clusterId Cluster id +// * @return Map of Keys and Values for the specified cluster in the relevant app. Each key can have multiple Values. +// * @throws MetaDataServiceClientExeption +// */ + public Map<String, Set<String>> getProperties (String appId, String clusterId) throws MetaDataServiceClientExeption; + +// /** +// * Retrieves the property key value pairs of the specified app +// * +// * @param appId Application id +// * @return Map of Keys and Values for the specified app. Each key can have multiple Values. +// * @throws MetaDataServiceClientExeption +// */ +// public Map<String, Set<String>> getProperties (String appId) throws MetaDataServiceClientExeption; +// +// /** +// * Retrieves the property values for the specified key of the relevant app +// * +// * @param appId Application id +// * @param propertyKey Key of the Property +// * @return Set of Values for specified Key of the relevant app. +// * @throws MetaDataServiceClientExeption +// */ + public Set<String> getProperty (String appId, String propertyKey) throws MetaDataServiceClientExeption; + + /** + * Retrieves the property values for the specified key of the relevant cluster and app + * + * @param appId Application id + * @param clusterId Cluster id + * @param propertyKey Key of the Property + * @return Set of Values for specified Key of the relevant cluster in the relevant app. + * @throws MetaDataServiceClientExeption + */ + public Set<String> getProperty (String appId, String clusterId, String propertyKey) throws MetaDataServiceClientExeption; + + /** + * Shutdown the MetaDataServiceClient. Should be called once after using the client. + * + * @throws MetaDataServiceClientExeption + */ + public void terminate () throws MetaDataServiceClientExeption; +} http://git-wip-us.apache.org/repos/asf/stratos/blob/448c13e3/components/org.apache.stratos.metadata.client/src/main/java/org/apache/stratos/metadata/client/MetaDataServiceClientManager.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.metadata.client/src/main/java/org/apache/stratos/metadata/client/MetaDataServiceClientManager.java b/components/org.apache.stratos.metadata.client/src/main/java/org/apache/stratos/metadata/client/MetaDataServiceClientManager.java new file mode 100644 index 0000000..e2057d3 --- /dev/null +++ b/components/org.apache.stratos.metadata.client/src/main/java/org/apache/stratos/metadata/client/MetaDataServiceClientManager.java @@ -0,0 +1,93 @@ +/* + * 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. + */ + +package org.apache.stratos.metadata.client; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.stratos.metadata.client.data.extractor.DataExtractor; +import org.apache.stratos.metadata.client.data.extractor.DefaultDataExtractor; +import org.apache.stratos.metadata.client.exception.DataExtractorException; +import org.apache.stratos.metadata.client.exception.MetaDataServiceClientExeption; +import org.apache.stratos.metadata.client.pojo.DataContext; + +import java.util.Collection; + +public class MetaDataServiceClientManager { + + private static final Log log = LogFactory.getLog(MetaDataServiceClientManager.class); + + private MetaDataServiceClient metaDataServiceClient; + + private DataExtractor dataExtractor; + + private String baseUrl; + + private String customDataExtractorClassName; + + + public MetaDataServiceClientManager () { + + readConfigurations(); + init(); + this.metaDataServiceClient = new DefaultMetaDataServiceClient(baseUrl); + } + + private void readConfigurations () { + //TODO: read configurations + } + + private void init () { + + metaDataServiceClient.initialize(); + //TODO: load the relevant customized class + // currently only the default DataExtractor is used + dataExtractor = new DefaultDataExtractor(); + } + + public void addExtractedData () { + + Collection<DataContext> dataContexts = null; + + try { + dataContexts = dataExtractor.getData(); + + } catch (DataExtractorException e) { + log.error("Unable to get extracted data", e); + } + + for (DataContext dataContext : dataContexts) { + if (dataContext.getPropertyValues() != null) { + for (String propertyValue : dataContext.getPropertyValues()) { + try { + metaDataServiceClient.addProperty(dataContext.getAppId(), dataContext.getClusterId(), + dataContext.getPropertyKey(), propertyValue); + + } catch (MetaDataServiceClientExeption e) { + log.error("Unable to add extracted data meta data service", e); + } + } + } + } + } + + public MetaDataServiceClient getMetaDataServiceClient() { + return metaDataServiceClient; + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/448c13e3/components/org.apache.stratos.metadata.client/src/main/java/org/apache/stratos/metadata/client/data/extractor/DataExtractor.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.metadata.client/src/main/java/org/apache/stratos/metadata/client/data/extractor/DataExtractor.java b/components/org.apache.stratos.metadata.client/src/main/java/org/apache/stratos/metadata/client/data/extractor/DataExtractor.java new file mode 100644 index 0000000..a3c1428 --- /dev/null +++ b/components/org.apache.stratos.metadata.client/src/main/java/org/apache/stratos/metadata/client/data/extractor/DataExtractor.java @@ -0,0 +1,34 @@ +/* + * 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. + */ + +package org.apache.stratos.metadata.client.data.extractor; + +import org.apache.stratos.metadata.client.exception.DataExtractorException; +import org.apache.stratos.metadata.client.pojo.DataContext; + +import java.util.Collection; + +public interface DataExtractor { + + public void initialize () throws DataExtractorException; + + public Collection<DataContext> getData () throws DataExtractorException; + + public void terminate () throws DataExtractorException; +} http://git-wip-us.apache.org/repos/asf/stratos/blob/448c13e3/components/org.apache.stratos.metadata.client/src/main/java/org/apache/stratos/metadata/client/data/extractor/DefaultDataExtractor.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.metadata.client/src/main/java/org/apache/stratos/metadata/client/data/extractor/DefaultDataExtractor.java b/components/org.apache.stratos.metadata.client/src/main/java/org/apache/stratos/metadata/client/data/extractor/DefaultDataExtractor.java new file mode 100644 index 0000000..c7743e8 --- /dev/null +++ b/components/org.apache.stratos.metadata.client/src/main/java/org/apache/stratos/metadata/client/data/extractor/DefaultDataExtractor.java @@ -0,0 +1,40 @@ +/* + * 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. + */ + +package org.apache.stratos.metadata.client.data.extractor; + +import org.apache.stratos.metadata.client.exception.DataExtractorException; +import org.apache.stratos.metadata.client.pojo.DataContext; + +import java.util.Collection; + +public class DefaultDataExtractor implements DataExtractor { + + public void initialize() throws DataExtractorException { + //To change body of implemented methods use File | Settings | File Templates. + } + + public Collection<DataContext> getData() throws DataExtractorException { + return null; //To change body of implemented methods use File | Settings | File Templates. + } + + public void terminate() throws DataExtractorException { + //To change body of implemented methods use File | Settings | File Templates. + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/448c13e3/components/org.apache.stratos.metadata.client/src/main/java/org/apache/stratos/metadata/client/exception/DataExtractorException.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.metadata.client/src/main/java/org/apache/stratos/metadata/client/exception/DataExtractorException.java b/components/org.apache.stratos.metadata.client/src/main/java/org/apache/stratos/metadata/client/exception/DataExtractorException.java new file mode 100644 index 0000000..835d71d --- /dev/null +++ b/components/org.apache.stratos.metadata.client/src/main/java/org/apache/stratos/metadata/client/exception/DataExtractorException.java @@ -0,0 +1,47 @@ +/* + * 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. + */ + +package org.apache.stratos.metadata.client.exception; + +public class DataExtractorException extends Exception { + + private String message; + + public DataExtractorException() { + super(); + } + + public DataExtractorException(String message, Throwable cause) { + super(message, cause); + this.message = message; + } + + public DataExtractorException(String message) { + super(message); + this.message = message; + } + + public DataExtractorException(Throwable cause) { + super(cause); + } + + public String getMessage() { + return message; + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/448c13e3/components/org.apache.stratos.metadata.client/src/main/java/org/apache/stratos/metadata/client/exception/MetaDataServiceClientExeption.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.metadata.client/src/main/java/org/apache/stratos/metadata/client/exception/MetaDataServiceClientExeption.java b/components/org.apache.stratos.metadata.client/src/main/java/org/apache/stratos/metadata/client/exception/MetaDataServiceClientExeption.java new file mode 100644 index 0000000..8ef5e37 --- /dev/null +++ b/components/org.apache.stratos.metadata.client/src/main/java/org/apache/stratos/metadata/client/exception/MetaDataServiceClientExeption.java @@ -0,0 +1,48 @@ +/* + * 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. + */ + +package org.apache.stratos.metadata.client.exception; + +public class MetaDataServiceClientExeption extends Exception { + + private String message; + + public MetaDataServiceClientExeption() { + super(); + } + + public MetaDataServiceClientExeption(String message, Throwable cause) { + super(message, cause); + this.message = message; + } + + public MetaDataServiceClientExeption(String message) { + super(message); + this.message = message; + } + + public MetaDataServiceClientExeption(Throwable cause) { + super(cause); + } + + public String getMessage() { + return message; + } + +} http://git-wip-us.apache.org/repos/asf/stratos/blob/448c13e3/components/org.apache.stratos.metadata.client/src/main/java/org/apache/stratos/metadata/client/exception/RestClientException.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.metadata.client/src/main/java/org/apache/stratos/metadata/client/exception/RestClientException.java b/components/org.apache.stratos.metadata.client/src/main/java/org/apache/stratos/metadata/client/exception/RestClientException.java new file mode 100644 index 0000000..f52af45 --- /dev/null +++ b/components/org.apache.stratos.metadata.client/src/main/java/org/apache/stratos/metadata/client/exception/RestClientException.java @@ -0,0 +1,48 @@ +/* + * 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. + */ + +package org.apache.stratos.metadata.client.exception; + +public class RestClientException extends Exception { + + private String message; + + public RestClientException() { + super(); + } + + public RestClientException(String message, Throwable cause) { + super(message, cause); + this.message = message; + } + + public RestClientException(String message) { + super(message); + this.message = message; + } + + public RestClientException(Throwable cause) { + super(cause); + } + + public String getMessage() { + return message; + } + +} http://git-wip-us.apache.org/repos/asf/stratos/blob/448c13e3/components/org.apache.stratos.metadata.client/src/main/java/org/apache/stratos/metadata/client/pojo/DataContext.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.metadata.client/src/main/java/org/apache/stratos/metadata/client/pojo/DataContext.java b/components/org.apache.stratos.metadata.client/src/main/java/org/apache/stratos/metadata/client/pojo/DataContext.java new file mode 100644 index 0000000..589c034 --- /dev/null +++ b/components/org.apache.stratos.metadata.client/src/main/java/org/apache/stratos/metadata/client/pojo/DataContext.java @@ -0,0 +1,58 @@ +/* + * 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. + */ + +package org.apache.stratos.metadata.client.pojo; + +import java.util.Set; + +public class DataContext { + + private String appId; + + private String clusterId; + + private String propertyKey; + + private Set<String> propertyValues; + + + public DataContext (String appId, String propertyKey, Set<String> propertyValues) { + + } + + public DataContext (String appId, String clusterId, String propertyKey, Set<String> propertyValues) { + + } + + public String getAppId() { + return appId; + } + + public String getClusterId() { + return clusterId; + } + + public String getPropertyKey() { + return propertyKey; + } + + public Set<String> getPropertyValues() { + return propertyValues; + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/448c13e3/components/org.apache.stratos.metadata.client/src/main/java/org/apache/stratos/metadata/client/rest/DefaultRestClient.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.metadata.client/src/main/java/org/apache/stratos/metadata/client/rest/DefaultRestClient.java b/components/org.apache.stratos.metadata.client/src/main/java/org/apache/stratos/metadata/client/rest/DefaultRestClient.java new file mode 100644 index 0000000..8c767e2 --- /dev/null +++ b/components/org.apache.stratos.metadata.client/src/main/java/org/apache/stratos/metadata/client/rest/DefaultRestClient.java @@ -0,0 +1,85 @@ +/* + * 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. + */ + +package org.apache.stratos.metadata.client.rest; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.http.HttpResponse; +import org.apache.http.client.HttpClient; +import org.apache.http.client.methods.HttpDelete; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.impl.client.DefaultHttpClient; +import org.apache.stratos.metadata.client.exception.RestClientException; + +import java.io.IOException; + +public class DefaultRestClient implements RestClient { + + private static Log log = LogFactory.getLog(DefaultRestClient.class); + + private HttpClient httpClient; + + public DefaultRestClient() { + this.httpClient = new DefaultHttpClient(); + } + + public HttpResponse doPost(String resourcePath, Object payload) throws RestClientException { + + HttpPost post = new HttpPost(resourcePath); + //TODO set params + try { + return httpClient.execute(post); + + } catch (IOException e) { + String errorMsg = "Error while executing POST statement"; + log.error(errorMsg, e); + throw new RestClientException(errorMsg, e); + } + } + + public HttpResponse doGet(String resourcePath) throws RestClientException { + + HttpGet get = new HttpGet(resourcePath); + + try { + return httpClient.execute(get); + + } catch (IOException e) { + String errorMsg = "Error while executing GET statement"; + log.error(errorMsg, e); + throw new RestClientException(errorMsg, e); + } + } + + public HttpResponse doDelete(String resourcePath) throws RestClientException { + + HttpDelete delete = new HttpDelete(resourcePath); + + try { + return httpClient.execute(delete); + + } catch (IOException e) { + String errorMsg = "Error while executing DELETE statement"; + log.error(errorMsg, e); + throw new RestClientException(errorMsg, e); + } + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/448c13e3/components/org.apache.stratos.metadata.client/src/main/java/org/apache/stratos/metadata/client/rest/RestClient.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.metadata.client/src/main/java/org/apache/stratos/metadata/client/rest/RestClient.java b/components/org.apache.stratos.metadata.client/src/main/java/org/apache/stratos/metadata/client/rest/RestClient.java new file mode 100644 index 0000000..5027735 --- /dev/null +++ b/components/org.apache.stratos.metadata.client/src/main/java/org/apache/stratos/metadata/client/rest/RestClient.java @@ -0,0 +1,32 @@ +/* + * 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. + */ + +package org.apache.stratos.metadata.client.rest; + +import org.apache.http.HttpResponse; +import org.apache.stratos.metadata.client.exception.RestClientException; + +public interface RestClient { + + public HttpResponse doPost (String resourcePath, Object payload) throws RestClientException; + + public HttpResponse doGet (String resourcePath) throws RestClientException; + + public HttpResponse doDelete (String resourcePath) throws RestClientException; +} http://git-wip-us.apache.org/repos/asf/stratos/blob/448c13e3/components/pom.xml ---------------------------------------------------------------------- diff --git a/components/pom.xml b/components/pom.xml index 322ccae..d1b1dc4 100644 --- a/components/pom.xml +++ b/components/pom.xml @@ -104,7 +104,8 @@ <module>org.apache.stratos.manager.styles</module> <module>org.apache.stratos.metadataservice</module> - + <!-- meta data client --> + <module>org.apache.stratos.metadata.client</module> </modules> <build>
