You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by at...@apache.org on 2010/01/08 21:13:14 UTC
svn commit: r897315 - in /incubator/aries/trunk/jmx/jmx-core/src:
main/java/org/apache/aries/jmx/provisioning/
test/java/org/apache/aries/jmx/provisioning/
Author: atk
Date: Fri Jan 8 20:13:13 2010
New Revision: 897315
URL: http://svn.apache.org/viewvc?rev=897315&view=rev
Log:
ARIES-34 Implement ProvisioningService MBean
Added:
incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/provisioning/
incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/provisioning/ProvisioningService.java (with props)
incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/provisioning/ProvisioningServiceMBeanHandler.java (with props)
incubator/aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/provisioning/
incubator/aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/provisioning/ProvisioningServiceMBeanHandlerTest.java (with props)
incubator/aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/provisioning/ProvisioningServiceTest.java (with props)
Added: incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/provisioning/ProvisioningService.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/provisioning/ProvisioningService.java?rev=897315&view=auto
==============================================================================
--- incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/provisioning/ProvisioningService.java (added)
+++ incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/provisioning/ProvisioningService.java Fri Jan 8 20:13:13 2010
@@ -0,0 +1,122 @@
+/**
+ * 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.aries.jmx.provisioning;
+
+import static org.osgi.jmx.JmxConstants.PROPERTIES_TYPE;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.Collection;
+import java.util.Dictionary;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.zip.ZipInputStream;
+
+import javax.management.openmbean.CompositeData;
+import javax.management.openmbean.TabularData;
+import javax.management.openmbean.TabularDataSupport;
+
+import org.apache.aries.jmx.codec.PropertyData;
+import org.osgi.jmx.service.provisioning.ProvisioningServiceMBean;
+
+/**
+ * Implementation of <code>ProvisioningServiceMBean</code>
+ *
+ * @version $Rev$ $Date$
+ */
+public class ProvisioningService implements ProvisioningServiceMBean {
+
+ private org.osgi.service.provisioning.ProvisioningService provisioningService;
+
+ /**
+ * Constructs new ProvisioningService instance
+ * @param provisioningService instance of org.osgi.service.provisioning.ProvisioningService service
+ */
+ public ProvisioningService(org.osgi.service.provisioning.ProvisioningService provisioningService){
+ this.provisioningService = provisioningService;
+ }
+
+ /**
+ * @see org.osgi.jmx.service.provisioning.ProvisioningServiceMBean#addInformation(java.lang.String)
+ */
+ public void addInformation(String zipURL) throws IOException {
+ if (zipURL == null || zipURL.length() < 1) {
+ throw new IllegalArgumentException("Argument zipURL cannot be null or empty");
+ }
+ InputStream is = createStream(zipURL);
+ ZipInputStream zis = new ZipInputStream(is);
+ try {
+ provisioningService.addInformation(zis);
+ } finally {
+ zis.close();
+ }
+ }
+
+ /**
+ * @see org.osgi.jmx.service.provisioning.ProvisioningServiceMBean#addInformation(javax.management.openmbean.TabularData)
+ */
+ public void addInformation(TabularData info) throws IOException {
+ Dictionary<String, Object> provisioningInfo = extractProvisioningDictionary(info);
+ provisioningService.addInformation(provisioningInfo);
+ }
+
+ /**
+ * @see org.osgi.jmx.service.provisioning.ProvisioningServiceMBean#listInformation()
+ */
+ @SuppressWarnings("unchecked")
+ public TabularData listInformation() throws IOException {
+ TabularData propertiesTable = new TabularDataSupport(PROPERTIES_TYPE);
+ Dictionary<String, Object> information = (Dictionary<String, Object>) provisioningService.getInformation();
+ if (information != null) {
+ Enumeration<String> keys = information.keys();
+ while (keys.hasMoreElements()) {
+ String key = keys.nextElement();
+ propertiesTable.put(PropertyData.newInstance(key, information.get(key)).toCompositeData());
+ }
+ }
+ return propertiesTable;
+ }
+
+ /**
+ * @see org.osgi.jmx.service.provisioning.ProvisioningServiceMBean#setInformation(javax.management.openmbean.TabularData)
+ */
+ public void setInformation(TabularData info) throws IOException {
+ Dictionary<String, Object> provisioningInfo = extractProvisioningDictionary(info);
+ provisioningService.setInformation(provisioningInfo);
+ }
+
+
+ @SuppressWarnings("unchecked")
+ protected Dictionary<String, Object> extractProvisioningDictionary(TabularData info) {
+ if (!PROPERTIES_TYPE.equals(info.getTabularType())) {
+ throw new IllegalArgumentException("Invalid TabularType [" + info.getTabularType() + "]");
+ }
+ Dictionary<String, Object> provisioningInfo = new Hashtable<String, Object>();
+ Collection<CompositeData> compositeData = (Collection<CompositeData>) info.values();
+ for (CompositeData row: compositeData) {
+ PropertyData<? extends Class> propertyData = PropertyData.from(row);
+ provisioningInfo.put(propertyData.getKey(), propertyData.getValue());
+ }
+ return provisioningInfo;
+ }
+
+ protected InputStream createStream(String url) throws IOException {
+ return new URL(url).openStream();
+ }
+
+}
Propchange: incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/provisioning/ProvisioningService.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/provisioning/ProvisioningService.java
------------------------------------------------------------------------------
svn:keywords = Revision Date
Added: incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/provisioning/ProvisioningServiceMBeanHandler.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/provisioning/ProvisioningServiceMBeanHandler.java?rev=897315&view=auto
==============================================================================
--- incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/provisioning/ProvisioningServiceMBeanHandler.java (added)
+++ incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/provisioning/ProvisioningServiceMBeanHandler.java Fri Jan 8 20:13:13 2010
@@ -0,0 +1,74 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * 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.aries.jmx.provisioning;
+
+import javax.management.NotCompliantMBeanException;
+import javax.management.StandardMBean;
+
+import org.apache.aries.jmx.AbstractCompendiumHandler;
+import org.apache.aries.jmx.Logger;
+import org.apache.aries.jmx.MBeanHandler;
+import org.apache.aries.jmx.agent.JMXAgentContext;
+import org.osgi.jmx.service.provisioning.ProvisioningServiceMBean;
+import org.osgi.service.log.LogService;
+
+/**
+ * <p>
+ * Implementation of <code>MBeanHandler</code> which manages the <code>ProvisioningServiceMBean</code> implementation
+ *
+ * @see MBeanHandler
+ *
+ * @version $Rev$ $Date$
+ */
+public class ProvisioningServiceMBeanHandler extends AbstractCompendiumHandler {
+
+ /**
+ * Constructs new ProvisioningServiceMBeanHandler instance
+ *
+ * @param agentContext
+ * JMXAgentContext instance
+ */
+ public ProvisioningServiceMBeanHandler(JMXAgentContext agentContext) {
+ super(agentContext, "org.osgi.service.provisioning.ProvisioningService");
+ }
+
+ /**
+ * @see org.apache.aries.jmx.AbstractCompendiumHandler#constructInjectMBean(java.lang.Object)
+ */
+ @Override
+ protected StandardMBean constructInjectMBean(Object targetService) {
+ ProvisioningService psMBean = new ProvisioningService(
+ (org.osgi.service.provisioning.ProvisioningService) targetService);
+ StandardMBean mbean = null;
+ try {
+ mbean = new StandardMBean(psMBean, ProvisioningServiceMBean.class);
+ } catch (NotCompliantMBeanException e) {
+ Logger logger = agentContext.getLogger();
+ logger.log(LogService.LOG_ERROR, "Failed to instantiate MBean for "
+ + ProvisioningServiceMBean.class.getName(), e);
+ }
+ return mbean;
+ }
+
+ /**
+ * @see org.apache.aries.jmx.MBeanHandler#getName()
+ */
+ public String getName() {
+ return ProvisioningServiceMBean.OBJECTNAME;
+ }
+
+}
Propchange: incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/provisioning/ProvisioningServiceMBeanHandler.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/provisioning/ProvisioningServiceMBeanHandler.java
------------------------------------------------------------------------------
svn:keywords = Revision Date
Added: incubator/aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/provisioning/ProvisioningServiceMBeanHandlerTest.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/provisioning/ProvisioningServiceMBeanHandlerTest.java?rev=897315&view=auto
==============================================================================
--- incubator/aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/provisioning/ProvisioningServiceMBeanHandlerTest.java (added)
+++ incubator/aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/provisioning/ProvisioningServiceMBeanHandlerTest.java Fri Jan 8 20:13:13 2010
@@ -0,0 +1,53 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.aries.jmx.provisioning;
+
+import static org.junit.Assert.assertNotNull;
+import static org.mockito.Mockito.mock;
+
+import javax.management.StandardMBean;
+
+import org.apache.aries.jmx.Logger;
+import org.apache.aries.jmx.agent.JMXAgentContext;
+import org.junit.Test;
+import org.osgi.framework.BundleContext;
+import org.osgi.service.provisioning.ProvisioningService;
+
+/**
+ *
+ *
+ * @version $Rev$ $Date$
+ */
+public class ProvisioningServiceMBeanHandlerTest {
+
+
+ @Test
+ public void testConstructInjectMBean() {
+
+ BundleContext bundleContext = mock(BundleContext.class);
+ Logger agentLogger = mock(Logger.class);
+ JMXAgentContext agentContext = new JMXAgentContext(bundleContext, null, agentLogger);
+ ProvisioningService provService = mock(ProvisioningService.class);
+
+ ProvisioningServiceMBeanHandler handler = new ProvisioningServiceMBeanHandler(agentContext);
+ StandardMBean mbean = handler.constructInjectMBean(provService);
+ assertNotNull(mbean);
+
+ }
+
+
+}
Propchange: incubator/aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/provisioning/ProvisioningServiceMBeanHandlerTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/provisioning/ProvisioningServiceMBeanHandlerTest.java
------------------------------------------------------------------------------
svn:keywords = Revision Date
Added: incubator/aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/provisioning/ProvisioningServiceTest.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/provisioning/ProvisioningServiceTest.java?rev=897315&view=auto
==============================================================================
--- incubator/aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/provisioning/ProvisioningServiceTest.java (added)
+++ incubator/aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/provisioning/ProvisioningServiceTest.java Fri Jan 8 20:13:13 2010
@@ -0,0 +1,155 @@
+/**
+ * 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.aries.jmx.provisioning;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import static org.osgi.jmx.JmxConstants.PROPERTIES_TYPE;
+import static org.osgi.service.provisioning.ProvisioningService.PROVISIONING_AGENT_CONFIG;
+import static org.osgi.service.provisioning.ProvisioningService.PROVISIONING_REFERENCE;
+import static org.osgi.service.provisioning.ProvisioningService.PROVISIONING_RSH_SECRET;
+import static org.osgi.service.provisioning.ProvisioningService.PROVISIONING_SPID;
+import static org.osgi.service.provisioning.ProvisioningService.PROVISIONING_UPDATE_COUNT;
+
+import java.io.InputStream;
+import java.util.Dictionary;
+import java.util.Hashtable;
+import java.util.zip.ZipInputStream;
+
+import javax.management.openmbean.TabularData;
+import javax.management.openmbean.TabularDataSupport;
+
+import org.apache.aries.jmx.codec.PropertyData;
+import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+
+/**
+ *
+ *
+ * @version $Rev$ $Date$
+ */
+public class ProvisioningServiceTest {
+
+
+ @Test
+ public void testAddInformation() throws Exception {
+
+ org.osgi.service.provisioning.ProvisioningService provService = mock(org.osgi.service.provisioning.ProvisioningService.class);
+ ProvisioningService mbean = new ProvisioningService(provService);
+ ProvisioningService spiedMBean = spy(mbean);
+
+ InputStream is = mock(InputStream.class);
+ doReturn(is).when(spiedMBean).createStream("file://prov.zip");
+
+ spiedMBean.addInformation("file://prov.zip");
+ verify(provService).addInformation(any(ZipInputStream.class));
+ verify(is).close();
+
+ }
+
+
+ @Test
+ @SuppressWarnings("unchecked")
+ public void testAddInformationWithTabularData() throws Exception {
+
+ org.osgi.service.provisioning.ProvisioningService provService = mock(org.osgi.service.provisioning.ProvisioningService.class);
+ ProvisioningService mbean = new ProvisioningService(provService);
+
+ TabularData data = new TabularDataSupport(PROPERTIES_TYPE);
+ PropertyData<byte[]> p1 = PropertyData.newInstance(PROVISIONING_AGENT_CONFIG, new byte[] { 20, 30, 40 });
+ data.put(p1.toCompositeData());
+ PropertyData<String> p2 = PropertyData.newInstance(PROVISIONING_SPID, "x.test");
+ data.put(p2.toCompositeData());
+
+ mbean.addInformation(data);
+ ArgumentCaptor<Dictionary> dictionaryArgument = ArgumentCaptor.forClass(Dictionary.class);
+ verify(provService).addInformation(dictionaryArgument.capture());
+
+ Dictionary<String, Object> info = dictionaryArgument.getValue();
+ assertEquals(2, info.size() );
+ assertArrayEquals(new byte[] { 20, 30, 40 }, (byte[]) info.get(PROVISIONING_AGENT_CONFIG));
+ assertEquals("x.test", info.get(PROVISIONING_SPID));
+
+ }
+
+
+ @Test
+ public void testListInformation() throws Exception {
+
+ org.osgi.service.provisioning.ProvisioningService provService = mock(org.osgi.service.provisioning.ProvisioningService.class);
+ ProvisioningService mbean = new ProvisioningService(provService);
+
+ Dictionary<String, Object> info = new Hashtable<String, Object>();
+ info.put(PROVISIONING_AGENT_CONFIG, new byte[] { 20, 30, 40 });
+ info.put(PROVISIONING_SPID, "x.test");
+ info.put(PROVISIONING_REFERENCE, "rsh://0.0.0.0/provX");
+ info.put(PROVISIONING_RSH_SECRET, new byte[] { 15, 25, 35 });
+ info.put(PROVISIONING_UPDATE_COUNT, 1);
+
+ when(provService.getInformation()).thenReturn(info);
+
+ TabularData provData = mbean.listInformation();
+ assertNotNull(provData);
+ assertEquals(PROPERTIES_TYPE, provData.getTabularType());
+ assertEquals(5, provData.values().size());
+ PropertyData<byte[]> agentConfig = PropertyData.from(provData.get(new Object[]{ PROVISIONING_AGENT_CONFIG }));
+ assertArrayEquals(new byte[] { 20, 30, 40 }, agentConfig.getValue());
+ PropertyData<String> spid = PropertyData.from(provData.get(new Object[] { PROVISIONING_SPID }));
+ assertEquals("x.test", spid.getValue());
+ PropertyData<String> ref = PropertyData.from(provData.get(new Object[] { PROVISIONING_REFERENCE }));
+ assertEquals("rsh://0.0.0.0/provX", ref.getValue());
+ PropertyData<byte[]> sec = PropertyData.from(provData.get(new Object[] { PROVISIONING_RSH_SECRET }));
+ assertArrayEquals(new byte[] { 15, 25, 35 }, sec.getValue());
+ PropertyData<Integer> count = PropertyData.from(provData.get(new Object[] { PROVISIONING_UPDATE_COUNT }));
+ assertEquals(new Integer(1), count.getValue());
+
+ }
+
+
+ @Test
+ @SuppressWarnings("unchecked")
+ public void testSetInformation() throws Exception {
+
+ org.osgi.service.provisioning.ProvisioningService provService = mock(org.osgi.service.provisioning.ProvisioningService.class);
+ ProvisioningService mbean = new ProvisioningService(provService);
+
+ TabularData data = new TabularDataSupport(PROPERTIES_TYPE);
+ PropertyData<String> p1 = PropertyData.newInstance(PROVISIONING_REFERENCE, "rsh://0.0.0.0/provX");
+ data.put(p1.toCompositeData());
+ PropertyData<String> p2 = PropertyData.newInstance(PROVISIONING_SPID, "x.test");
+ data.put(p2.toCompositeData());
+
+ mbean.setInformation(data);
+
+ ArgumentCaptor<Dictionary> dictionaryArgument = ArgumentCaptor.forClass(Dictionary.class);
+ verify(provService).setInformation(dictionaryArgument.capture());
+
+ Dictionary<String, Object> info = dictionaryArgument.getValue();
+ assertEquals(2, info.size() );
+ assertEquals("rsh://0.0.0.0/provX", info.get(PROVISIONING_REFERENCE));
+ assertEquals("x.test", info.get(PROVISIONING_SPID));
+
+ }
+
+}
Propchange: incubator/aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/provisioning/ProvisioningServiceTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/provisioning/ProvisioningServiceTest.java
------------------------------------------------------------------------------
svn:keywords = Revision Date