From f22b6251c175e8a3cf527697e079abe0bc35a414 Mon Sep 17 00:00:00 2001 From: charithag Date: Fri, 22 Jan 2016 11:52:58 +0530 Subject: [PATCH] Add Configuration service and removed url printer --- .../IotDeviceManagementServiceComponent.java | 17 +++--- .../mgt/iot/service/ConfigurationService.java | 51 ++++++++++++++++ .../iot/service/ConfigurationServiceImpl.java | 41 +++++++++++++ .../mgt/iot/startup/StartupUrlPrinter.java | 60 ------------------- 4 files changed, 101 insertions(+), 68 deletions(-) create mode 100644 components/device-mgt-iot/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/service/ConfigurationService.java create mode 100644 components/device-mgt-iot/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/service/ConfigurationServiceImpl.java delete mode 100644 components/device-mgt-iot/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/startup/StartupUrlPrinter.java diff --git a/components/device-mgt-iot/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/internal/IotDeviceManagementServiceComponent.java b/components/device-mgt-iot/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/internal/IotDeviceManagementServiceComponent.java index 138425e619..a34e4a3848 100644 --- a/components/device-mgt-iot/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/internal/IotDeviceManagementServiceComponent.java +++ b/components/device-mgt-iot/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/internal/IotDeviceManagementServiceComponent.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. * * WSO2 Inc. licenses this file to you under the Apache License, * Version 2.0 (the "License"); you may not use this file except @@ -11,7 +11,7 @@ * 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 + * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ @@ -22,7 +22,6 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.osgi.framework.BundleContext; import org.osgi.service.component.ComponentContext; -import org.wso2.carbon.core.ServerStartupObserver; import org.wso2.carbon.databridge.core.DataBridgeReceiverService; import org.wso2.carbon.device.mgt.iot.UserManagement; import org.wso2.carbon.device.mgt.iot.analytics.statistics.IoTEventsStatisticsClient; @@ -33,9 +32,10 @@ import org.wso2.carbon.device.mgt.iot.config.server.DeviceManagementConfiguratio import org.wso2.carbon.device.mgt.iot.controlqueue.xmpp.XmppConfig; import org.wso2.carbon.device.mgt.iot.controlqueue.xmpp.XmppServerClient; import org.wso2.carbon.device.mgt.iot.exception.DeviceControllerException; +import org.wso2.carbon.device.mgt.iot.service.ConfigurationService; +import org.wso2.carbon.device.mgt.iot.service.ConfigurationServiceImpl; import org.wso2.carbon.device.mgt.iot.service.DeviceTypeService; import org.wso2.carbon.device.mgt.iot.service.DeviceTypeServiceImpl; -import org.wso2.carbon.device.mgt.iot.startup.StartupUrlPrinter; import org.wso2.carbon.device.mgt.iot.util.iotdevice.dao.IotDeviceManagementDAOFactory; import org.wso2.carbon.device.mgt.iot.util.iotdevice.dao.util.IotDeviceManagementDAOUtil; import org.wso2.carbon.device.mgt.iot.util.iotdevice.exception.IotDeviceMgtPluginException; @@ -85,8 +85,8 @@ public class IotDeviceManagementServiceComponent { try { - BundleContext bundleContext = ctx.getBundleContext(); /* Initialize the data source - configuration */ + BundleContext bundleContext = ctx.getBundleContext(); + /* Initialize the data source configuration */ DeviceManagementConfigurationManager.getInstance().initConfig(); IotDeviceTypeConfigurationManager.getInstance().initConfig(); Map dsConfigMap = @@ -127,11 +127,12 @@ public class IotDeviceManagementServiceComponent { bundleContext.registerService(DeviceTypeService.class.getName(), new DeviceTypeServiceImpl(), null); + bundleContext.registerService(ConfigurationService.class.getName(), + new ConfigurationServiceImpl(), null); + if (log.isDebugEnabled()) { log.debug("Iot Device Management Service Component has been successfully activated"); } - - bundleContext.registerService(ServerStartupObserver.class, new StartupUrlPrinter(), null); } catch (Throwable e) { log.error("Error occurred while activating Iot Device Management Service Component", e); } diff --git a/components/device-mgt-iot/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/service/ConfigurationService.java b/components/device-mgt-iot/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/service/ConfigurationService.java new file mode 100644 index 0000000000..a27f4523ae --- /dev/null +++ b/components/device-mgt-iot/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/service/ConfigurationService.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. 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.wso2.carbon.device.mgt.iot.service; + +import org.wso2.carbon.device.mgt.iot.config.server.datasource.ControlQueue; +import org.wso2.carbon.device.mgt.iot.config.server.datasource.DeviceManagementConfiguration; +import org.wso2.carbon.device.mgt.iot.config.server.datasource.DeviceMgtServerInfo; + +public interface ConfigurationService { + + + /** + * Retrieve all configurations in devicemgt-config.xml + * + * @return Complete set of configurations + */ + DeviceManagementConfiguration getDeviceCloudMgtConfig(); + + + /** + * Retrieve control queue configurations + * + * @param name of the control queue + * @return control queue configs + */ + ControlQueue getControlQueue(String name); + + + /** + * Retrieve device management server information + * + * @return device management server information + */ + DeviceMgtServerInfo getDeviceManagementServerInfo(); +} diff --git a/components/device-mgt-iot/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/service/ConfigurationServiceImpl.java b/components/device-mgt-iot/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/service/ConfigurationServiceImpl.java new file mode 100644 index 0000000000..3b3322f30d --- /dev/null +++ b/components/device-mgt-iot/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/service/ConfigurationServiceImpl.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. 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.wso2.carbon.device.mgt.iot.service; + +import org.wso2.carbon.device.mgt.iot.config.server.datasource.ControlQueue; +import org.wso2.carbon.device.mgt.iot.config.server.datasource.DeviceManagementConfiguration; +import org.wso2.carbon.device.mgt.iot.config.server.datasource.DeviceMgtServerInfo; + +public class ConfigurationServiceImpl implements ConfigurationService { + + @Override + public DeviceManagementConfiguration getDeviceCloudMgtConfig() { + return null; + } + + @Override + public ControlQueue getControlQueue(String name) { + return null; + } + + @Override + public DeviceMgtServerInfo getDeviceManagementServerInfo() { + return null; + } +} diff --git a/components/device-mgt-iot/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/startup/StartupUrlPrinter.java b/components/device-mgt-iot/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/startup/StartupUrlPrinter.java deleted file mode 100644 index a0e24da7f7..0000000000 --- a/components/device-mgt-iot/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/startup/StartupUrlPrinter.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. 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.wso2.carbon.device.mgt.iot.startup; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.core.ServerStartupObserver; -import org.wso2.carbon.device.mgt.iot.internal.IotDeviceManagementServiceComponent; -import org.wso2.carbon.utils.CarbonUtils; -import org.wso2.carbon.utils.ConfigurationContextService; -import org.wso2.carbon.utils.NetworkUtils; - -public class StartupUrlPrinter implements ServerStartupObserver { - private static final Log log = LogFactory.getLog(StartupUrlPrinter.class); - @Override - public void completingServerStartup() { - - } - - @Override - public void completedServerStartup() { - printUrl(); - - - } - private void printUrl() { - // Hostname - String hostName = "localhost"; - try { - hostName = NetworkUtils.getMgtHostName(); - } catch (Exception ignored) { - } - // HTTPS port - String mgtConsoleTransport = CarbonUtils.getManagementTransport(); - ConfigurationContextService configContextService = IotDeviceManagementServiceComponent.configurationContextService; - - int httpsPort = CarbonUtils.getTransportPort(configContextService, mgtConsoleTransport); - - log.info("Api Store: https://" + hostName + ":" + httpsPort + "/api-store"); - log.info("IOT Server - Device Store: https://" + hostName + ":" + httpsPort + "/store"); - log.info("IOT Server - Device Publisher: https://" + hostName + ":" + httpsPort + "/publisher"); - } - -}