Repository: stratos Updated Branches: refs/heads/4.0.0-grouping 36649e99d -> 8f889e6c7
improving 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/8f889e6c Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/8f889e6c Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/8f889e6c Branch: refs/heads/4.0.0-grouping Commit: 8f889e6c72e027642806097ac9ab42c138072ffa Parents: 36649e9 Author: Isuru Haththotuwa <[email protected]> Authored: Fri Sep 19 19:40:06 2014 +0530 Committer: Isuru Haththotuwa <[email protected]> Committed: Fri Sep 19 19:40:06 2014 +0530 ---------------------------------------------------------------------- .../client/config/MetaDataClientConfig.java | 10 +-- .../factory/MetaDataExtractorFactory.java | 52 ++++++++++++ .../sample/MetaDataServiceClientManager.java | 81 ------------------ .../sample/MetaDataServiceClientSample.java | 86 ++++++++++++++++++++ 4 files changed, 143 insertions(+), 86 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/stratos/blob/8f889e6c/components/org.apache.stratos.metadata.client/src/main/java/org/apache/stratos/metadata/client/config/MetaDataClientConfig.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.metadata.client/src/main/java/org/apache/stratos/metadata/client/config/MetaDataClientConfig.java b/components/org.apache.stratos.metadata.client/src/main/java/org/apache/stratos/metadata/client/config/MetaDataClientConfig.java index a44010c..a9e8c92 100644 --- a/components/org.apache.stratos.metadata.client/src/main/java/org/apache/stratos/metadata/client/config/MetaDataClientConfig.java +++ b/components/org.apache.stratos.metadata.client/src/main/java/org/apache/stratos/metadata/client/config/MetaDataClientConfig.java @@ -23,7 +23,7 @@ public class MetaDataClientConfig { private String metaDataServiceBaseUrl; - private String customExtractorClassName; + private String extractorClassName; private static volatile MetaDataClientConfig metaDataClientConfig; @@ -31,8 +31,8 @@ public class MetaDataClientConfig { readConfig(); } - private void readConfig () { - // TODO: read all configurations; metaDataServiceBaseUrl, customExtractorClassName + private void readConfig () throws RuntimeException{ + // TODO: read all configurations; metaDataServiceBaseUrl, extractorClassName. cannot be empty } public static MetaDataClientConfig getInstance () { @@ -52,7 +52,7 @@ public class MetaDataClientConfig { return metaDataServiceBaseUrl; } - public String getCustomExtractorClassName() { - return customExtractorClassName; + public String getExtractorClassName() { + return extractorClassName; } } http://git-wip-us.apache.org/repos/asf/stratos/blob/8f889e6c/components/org.apache.stratos.metadata.client/src/main/java/org/apache/stratos/metadata/client/factory/MetaDataExtractorFactory.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.metadata.client/src/main/java/org/apache/stratos/metadata/client/factory/MetaDataExtractorFactory.java b/components/org.apache.stratos.metadata.client/src/main/java/org/apache/stratos/metadata/client/factory/MetaDataExtractorFactory.java new file mode 100644 index 0000000..c9d5fc8 --- /dev/null +++ b/components/org.apache.stratos.metadata.client/src/main/java/org/apache/stratos/metadata/client/factory/MetaDataExtractorFactory.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * 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.factory; + +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.exception.MetaDataServiceClientExeption; + +public class MetaDataExtractorFactory { + + private static final Log log = LogFactory.getLog(MetaDataExtractorFactory.class); + + public static DataExtractor getMetaDataServiceClient (String clazzName) throws RuntimeException { + + try { + return (DataExtractor) DataExtractor.class.getClassLoader().loadClass(clazzName).newInstance(); + + } catch (InstantiationException e) { + String errorMsg = "Unable to instatiate class " + clazzName; + log.error(errorMsg, e); + throw new RuntimeException(errorMsg, e); + + } catch (IllegalAccessException e) { + String errorMsg = "Unable to instatiate class " + clazzName; + log.error(errorMsg, e); + throw new RuntimeException(errorMsg, e); + + } catch (ClassNotFoundException e) { + String errorMsg = "Unable to instatiate class " + clazzName; + log.error(errorMsg, e); + throw new RuntimeException(errorMsg, e); + } + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/8f889e6c/components/org.apache.stratos.metadata.client/src/main/java/org/apache/stratos/metadata/client/sample/MetaDataServiceClientManager.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.metadata.client/src/main/java/org/apache/stratos/metadata/client/sample/MetaDataServiceClientManager.java b/components/org.apache.stratos.metadata.client/src/main/java/org/apache/stratos/metadata/client/sample/MetaDataServiceClientManager.java deleted file mode 100644 index 36cecd2..0000000 --- a/components/org.apache.stratos.metadata.client/src/main/java/org/apache/stratos/metadata/client/sample/MetaDataServiceClientManager.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * 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.sample; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.stratos.metadata.client.DefaultMetaDataServiceClient; -import org.apache.stratos.metadata.client.MetaDataServiceClient; -import org.apache.stratos.metadata.client.config.MetaDataClientConfig; -import org.apache.stratos.metadata.client.data.extractor.DataExtractor; - -public class MetaDataServiceClientManager { - - private static final Log log = LogFactory.getLog(MetaDataServiceClientManager.class); - - private MetaDataServiceClient metaDataServiceClient; - - private DataExtractor dataExtractor; - - private MetaDataClientConfig metaDataClientConfig; - - - public MetaDataServiceClientManager () { - initialize(); - } - - private void initialize() { - - metaDataClientConfig = MetaDataClientConfig.getInstance(); - metaDataServiceClient = new DefaultMetaDataServiceClient(metaDataClientConfig.getMetaDataServiceBaseUrl()); - metaDataServiceClient.initialize(); - //TODO: load the relevant customized class using customDataExtractorClassName - // currently only the default DataExtractor is used - dataExtractor = new DefaultDataExtractor(); - dataExtractor.initialize(); - } - -// 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); -// } -// } -// } -// } -// } - -} http://git-wip-us.apache.org/repos/asf/stratos/blob/8f889e6c/components/org.apache.stratos.metadata.client/src/main/java/org/apache/stratos/metadata/client/sample/MetaDataServiceClientSample.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.metadata.client/src/main/java/org/apache/stratos/metadata/client/sample/MetaDataServiceClientSample.java b/components/org.apache.stratos.metadata.client/src/main/java/org/apache/stratos/metadata/client/sample/MetaDataServiceClientSample.java new file mode 100644 index 0000000..3a67768 --- /dev/null +++ b/components/org.apache.stratos.metadata.client/src/main/java/org/apache/stratos/metadata/client/sample/MetaDataServiceClientSample.java @@ -0,0 +1,86 @@ +/* + * 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.sample; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.stratos.metadata.client.DefaultMetaDataServiceClient; +import org.apache.stratos.metadata.client.MetaDataServiceClient; +import org.apache.stratos.metadata.client.config.MetaDataClientConfig; +import org.apache.stratos.metadata.client.data.extractor.DataExtractor; +import org.apache.stratos.metadata.client.exception.DataExtractorException; +import org.apache.stratos.metadata.client.exception.MetaDataServiceClientExeption; +import org.apache.stratos.metadata.client.factory.MetaDataExtractorFactory; +import org.apache.stratos.metadata.client.pojo.DataContext; + +import java.util.Collection; + +public class MetaDataServiceClientSample { + + private static final Log log = LogFactory.getLog(MetaDataServiceClientSample.class); + + private MetaDataServiceClient metaDataServiceClient; + + private DataExtractor dataExtractor; + + private MetaDataClientConfig metaDataClientConfig; + + + public MetaDataServiceClientSample() { + initialize(); + } + + private void initialize() { + + metaDataClientConfig = MetaDataClientConfig.getInstance(); + metaDataServiceClient = new DefaultMetaDataServiceClient(metaDataClientConfig. + getMetaDataServiceBaseUrl()); + metaDataServiceClient.initialize(); + dataExtractor = MetaDataExtractorFactory.getMetaDataServiceClient(metaDataClientConfig. + getExtractorClassName()); + } + + public void addExtractedData (Object someObj) { + + Collection<DataContext> dataContexts = null; + + try { + dataContexts = dataExtractor.getData(someObj); + + } 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); + } + } + } + } + } + +}
