You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by ff...@apache.org on 2009/02/05 09:43:02 UTC
svn commit: r741047 [1/2] - in /servicemix/smx4/nmr/trunk/jbi:
deployer/src/main/java/org/apache/servicemix/jbi/deployer/handler/
management/src/main/java/org/apache/servicemix/jbi/management/
management/src/main/resources/META-INF/spring/
Author: ffang
Date: Thu Feb 5 08:43:01 2009
New Revision: 741047
URL: http://svn.apache.org/viewvc?rev=741047&view=rev
Log:
[SMX4NMR-17]initially make MBean working for install/uninstall/stop/start/shutdown component operations
Added:
servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/AdminCommandsService.java (with props)
servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/AdminCommandsServiceMBean.java (with props)
servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/AdminService.java (with props)
servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/DeploymentService.java (with props)
servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/InstallationContextImpl.java (with props)
servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/InstallationService.java (with props)
servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/Installer.java (with props)
servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/ManagementSupport.java (with props)
Modified:
servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/handler/Transformer.java
servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/DefaultNamingStrategy.java
servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/ManagedJbiRegistry.java
servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/NamingStrategy.java
servicemix/smx4/nmr/trunk/jbi/management/src/main/resources/META-INF/spring/servicemix-jbi-management.xml
Modified: servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/handler/Transformer.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/handler/Transformer.java?rev=741047&r1=741046&r2=741047&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/handler/Transformer.java (original)
+++ servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/handler/Transformer.java Thu Feb 5 08:43:01 2009
@@ -99,5 +99,13 @@
jos.close();
jis.close();
}
+
+ public static Descriptor getDescriptor(File jbiArtifact) throws Exception {
+ JarFile jar = new JarFile(jbiArtifact);
+ JarEntry jarEntry = jar.getJarEntry("META-INF/jbi.xml");
+ InputStream is = jar.getInputStream(jarEntry);
+ Descriptor desc = DescriptorFactory.buildDescriptor(is);
+ return desc;
+ }
}
Added: servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/AdminCommandsService.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/AdminCommandsService.java?rev=741047&view=auto
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/AdminCommandsService.java (added)
+++ servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/AdminCommandsService.java Thu Feb 5 08:43:01 2009
@@ -0,0 +1,346 @@
+/*
+ * 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.servicemix.jbi.management;
+
+
+import javax.jbi.JBIException;
+import javax.jbi.management.LifeCycleMBean;
+
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.servicemix.jbi.deployer.Component;
+import org.apache.servicemix.jbi.deployer.impl.Deployer;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.springframework.osgi.context.BundleContextAware;
+
+public class AdminCommandsService implements AdminCommandsServiceMBean, BundleContextAware {
+
+ private static final Log LOGGER = LogFactory.getLog(AdminCommandsService.class);
+
+ private AdminService adminService;
+ private InstallationService installationService;
+ private BundleContext bundleContext;
+ private DeploymentService deploymentService;
+
+
+ protected interface ComponentCallback {
+ void doWithComponent(Component component) throws JBIException;
+ }
+
+ protected void executeWithComponent(String name, ComponentCallback callback) throws JBIException {
+ ServiceReference ref = getAdminService().getComponentServiceReference("(" + Deployer.NAME + "=" + name + ")");
+ if (ref == null) {
+ throw new JBIException("Component '" + name + "' not found");
+ }
+ Component component = (Component) bundleContext.getService(ref);
+ try {
+ callback.doWithComponent(component);
+ } finally {
+ bundleContext.ungetService(ref);
+ }
+ }
+
+ /**
+ * Install a JBI component (a Service Engine or Binding Component)
+ *
+ * @param file
+ * jbi component archive to install
+ * @param props
+ * installation properties
+ * @return
+ */
+ public String installComponent(String fileName, boolean deferException) throws Exception {
+ try {
+ getInstallationService().install(fileName, null, false);
+ return ManagementSupport.createSuccessMessage("installComponent", fileName);
+ } catch (Exception e) {
+ throw ManagementSupport.failure("installComponent", fileName, e);
+ }
+ }
+
+
+
+ /**
+ * Uninstalls a previously install JBI Component (a Service Engine or
+ * Binding Component)
+ *
+ * @param name
+ * @return
+ */
+ public String uninstallComponent(String name) throws Exception {
+ try {
+ executeWithComponent(name, new ComponentCallback() {
+ public void doWithComponent(Component comp) throws JBIException {
+ try {
+ if (comp == null) {
+ throw ManagementSupport.failure(
+ "uninstallComponent", "Component '"
+ + comp.getName()
+ + "' is not installed.");
+ }
+ if (!comp.getCurrentState().equals(
+ LifeCycleMBean.SHUTDOWN)) {
+ throw ManagementSupport.failure(
+ "uninstallComponent", "Component '"
+ + comp.getName()
+ + "' is not shut down.");
+ }
+ boolean success = installationService.unloadInstaller(
+ comp.getName(), true);
+ if (!success) {
+ throw new RuntimeException();
+ }
+ } catch (Exception e) {
+ throw new JBIException(e);
+ }
+
+ }
+ });
+ } catch (Exception e) {
+ throw ManagementSupport.failure("uninstallComponent", name, e);
+ }
+ return ManagementSupport.createSuccessMessage("uninstallComponent",
+ name);
+ }
+
+ /**
+ * Installs a Shared Library.
+ *
+ * @param file
+ * @return
+ */
+ public String installSharedLibrary(String file, boolean deferException) throws Exception {
+ return null;
+ /*if (deferException) {
+ container.updateExternalArchive(file);
+ return ManagementSupport.createSuccessMessage("installSharedLibrary", file);
+ } else {
+ return installationService.installSharedLibrary(file);
+ }*/
+ }
+
+ /**
+ * Uninstalls a previously installed Shared Library.
+ *
+ * @param name
+ * @return
+ */
+ public String uninstallSharedLibrary(String name) throws Exception {
+ return ManagementSupport.createSuccessMessage("to be done");
+ }
+
+ /**
+ * Starts a particular Component (Service Engine or Binding Component).
+ *
+ * @param name
+ * @return
+ */
+ public String startComponent(String name) throws Exception {
+ try {
+ executeWithComponent(name, new ComponentCallback() {
+ public void doWithComponent(Component component) throws JBIException {
+ component.start();
+ }
+ });
+ return ManagementSupport.createSuccessMessage("startComponent", name);
+ } catch (Exception e) {
+ throw ManagementSupport.failure("startComponent", name, e);
+ }
+ }
+
+ /**
+ * Stops a particular Component (Service Engine or Binding Component).
+ *
+ * @param name
+ * @return
+ */
+ public String stopComponent(String name) throws Exception {
+ try {
+ executeWithComponent(name, new ComponentCallback() {
+ public void doWithComponent(Component component) throws JBIException {
+ component.stop();
+ }
+ });
+ return ManagementSupport.createSuccessMessage("stopComponent", name);
+ } catch (Exception e) {
+ throw ManagementSupport.failure("stopComponent", name, e);
+ }
+ }
+
+ /**
+ * Shuts down a particular Component.
+ *
+ * @param name
+ * @return
+ */
+ public String shutdownComponent(String name) throws Exception {
+ try {
+ executeWithComponent(name, new ComponentCallback() {
+ public void doWithComponent(Component component) throws JBIException {
+ component.shutDown();
+ }
+ });
+ return ManagementSupport.createSuccessMessage("shutdownComponent", name);
+ } catch (Exception e) {
+ throw ManagementSupport.failure("shutdownComponent", name, e);
+ }
+ }
+
+ /**
+ * Deploys a Service Assembly.
+ *
+ * @param file
+ * @return
+ */
+ public String deployServiceAssembly(String file, boolean deferException) throws Exception {
+ return null;
+ /*if (deferException) {
+ container.updateExternalArchive(file);
+ return ManagementSupport.createSuccessMessage("deployServiceAssembly", file);
+ } else {
+ return deploymentService.deploy(file);
+ }*/
+ }
+
+ /**
+ * Undeploys a previously deployed service assembly.
+ *
+ * @param name
+ * @return
+ */
+ public String undeployServiceAssembly(String name) throws Exception {
+ return getDeploymentService().undeploy(name);
+ }
+
+ /**
+ * Starts a service assembly.
+ *
+ * @param name
+ * @return
+ */
+ public String startServiceAssembly(String name) throws Exception {
+ return getDeploymentService().start(name);
+ }
+
+ /**
+ * Stops a particular service assembly.
+ *
+ * @param name
+ * @return
+ */
+ public String stopServiceAssembly(String name) throws Exception {
+ return getDeploymentService().stop(name);
+ }
+
+ /**
+ * Shuts down a particular service assembly.
+ *
+ * @param name
+ * @return
+ */
+ public String shutdownServiceAssembly(String name) throws Exception {
+ return getDeploymentService().shutDown(name);
+ }
+
+ /**
+ * load an archive from an external location and starts it The archive can
+ * be a Component, Service Assembly or Shared Library.
+ *
+ * @param location -
+ * can either be a url or filename (if relative - must be
+ * relative to the container)
+ * @return status
+ * @throws Exception
+ */
+ public String installArchive(String location) throws Exception {
+ return ManagementSupport.createSuccessMessage("to be done");
+ }
+
+ /**
+ * Prints information about all components (Service Engine or Binding
+ * Component) installed
+ *
+ * @param serviceEngines
+ * @param bindingComponents
+ * @param state
+ * @param sharedLibraryName
+ * @param serviceAssemblyName
+ * @return list of components in an XML blob
+ */
+ public String listComponents(boolean excludeSEs, boolean excludeBCs, String requiredState,
+ String sharedLibraryName, String serviceAssemblyName) throws Exception {
+ // validate requiredState
+ return ManagementSupport.createSuccessMessage("to be done");
+ }
+
+ /**
+ * Prints information about shared libraries installed.
+ *
+ * @param componentName
+ * @param sharedLibraryName
+ * @return
+ */
+ public String listSharedLibraries(String componentName, String sharedLibraryName) throws Exception {
+ return ManagementSupport.createSuccessMessage("to be done");
+ }
+
+ /**
+ * Prints information about service assemblies deployed.
+ *
+ * @param state
+ * @param componentName
+ * @param serviceAssemblyName
+ * @return
+ */
+ public String listServiceAssemblies(String state, String componentName, String serviceAssemblyName) throws Exception {
+ return ManagementSupport.createSuccessMessage("to be done");
+ }
+
+ public void setBundleContext(BundleContext bundleContext) {
+ this.bundleContext = bundleContext;
+ }
+
+ public BundleContext getBundleContext() {
+ return bundleContext;
+ }
+ public void setInstallationService(InstallationService installationService) {
+ this.installationService = installationService;
+ }
+
+ public InstallationService getInstallationService() {
+ return installationService;
+ }
+
+ public void setDeploymentService(DeploymentService deploymentService) {
+ this.deploymentService = deploymentService;
+ }
+
+ public DeploymentService getDeploymentService() {
+ return deploymentService;
+ }
+
+ public void setAdminService(AdminService adminService) {
+ this.adminService = adminService;
+ }
+
+ public AdminService getAdminService() {
+ return adminService;
+ }
+
+}
Propchange: servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/AdminCommandsService.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/AdminCommandsService.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/AdminCommandsServiceMBean.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/AdminCommandsServiceMBean.java?rev=741047&view=auto
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/AdminCommandsServiceMBean.java (added)
+++ servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/AdminCommandsServiceMBean.java Thu Feb 5 08:43:01 2009
@@ -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.servicemix.jbi.management;
+
+import java.util.Properties;
+
+
+
+public interface AdminCommandsServiceMBean {
+ String installComponent(String file, boolean deferException) throws Exception;
+ String uninstallComponent(String name) throws Exception;
+ String installSharedLibrary(String file, boolean deferException) throws Exception;
+ String uninstallSharedLibrary(String name) throws Exception;
+ String startComponent(String name) throws Exception;
+ String stopComponent(String name) throws Exception;
+ String shutdownComponent(String name) throws Exception;
+ String deployServiceAssembly(String file, boolean deferException) throws Exception;
+ String undeployServiceAssembly(String name) throws Exception;
+ String startServiceAssembly(String name) throws Exception;
+ String stopServiceAssembly(String name) throws Exception;
+ String shutdownServiceAssembly(String name) throws Exception;
+ String installArchive(String location) throws Exception;
+ String listComponents(boolean excludeSEs,
+ boolean excludeBCs,
+ String requiredState,
+ String sharedLibraryName,
+ String serviceAssemblyName) throws Exception;
+ String listSharedLibraries(String componentName,
+ String sharedLibraryName) throws Exception;
+ String listServiceAssemblies(String state,
+ String componentName,
+ String serviceAssemblyName) throws Exception;
+}
+
Propchange: servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/AdminCommandsServiceMBean.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/AdminCommandsServiceMBean.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/AdminService.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/AdminService.java?rev=741047&view=auto
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/AdminService.java (added)
+++ servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/AdminService.java Thu Feb 5 08:43:01 2009
@@ -0,0 +1,121 @@
+/*
+ * 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.servicemix.jbi.management;
+
+import javax.jbi.management.AdminServiceMBean;
+import javax.management.ObjectName;
+
+import org.apache.servicemix.jbi.deployer.impl.Deployer;
+import org.apache.servicemix.jbi.runtime.impl.ManagementContext;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.springframework.osgi.context.BundleContextAware;
+import org.springframework.osgi.util.OsgiServiceReferenceUtils;
+
+/**
+ */
+public class AdminService implements AdminServiceMBean, BundleContextAware {
+
+ private BundleContext bundleContext;
+ private DefaultNamingStrategy namingStrategy;
+
+ public BundleContext getBundleContext() {
+ return bundleContext;
+ }
+
+ public void setBundleContext(BundleContext bundleContext) {
+ this.bundleContext = bundleContext;
+ }
+
+
+ public void setNamingStrategy(DefaultNamingStrategy namingStrategy) {
+ this.namingStrategy = namingStrategy;
+ }
+
+ public DefaultNamingStrategy getNamingStrategy() {
+ return namingStrategy;
+ }
+
+ protected ObjectName getComponentObjectName(ServiceReference ref) {
+ String name = (String) ref.getProperty(Deployer.NAME);
+ return namingStrategy.createCustomComponentMBeanName(name, "LifeCycle");
+ }
+
+ protected ServiceReference getComponentServiceReference(String filter) {
+ return OsgiServiceReferenceUtils.getServiceReference(
+ getBundleContext(),
+ org.apache.servicemix.jbi.deployer.Component.class.getName(),
+ filter);
+ }
+
+ protected ServiceReference[] getComponentServiceReferences(String filter) {
+ return OsgiServiceReferenceUtils.getServiceReferences(
+ getBundleContext(),
+ org.apache.servicemix.jbi.deployer.Component.class.getName(),
+ filter);
+ }
+
+ public ObjectName[] getBindingComponents() {
+ String filter = "(" + Deployer.TYPE + "=binding-component)";
+ ServiceReference refs[] = getComponentServiceReferences(filter);
+ ObjectName[] names = new ObjectName[refs.length];
+ for (int i = 0; i < refs.length; i++) {
+ names[i] = getComponentObjectName(refs[i]);
+ }
+ return names;
+ }
+
+ public ObjectName getComponentByName(String name) {
+ String filter = "(" + Deployer.NAME + "=" + name + ")";
+ ServiceReference ref = getComponentServiceReference(filter);
+ return getComponentObjectName(ref);
+ }
+
+ public ObjectName[] getEngineComponents() {
+ String filter = "(" + Deployer.TYPE + "=service-engine)";
+ ServiceReference refs[] = getComponentServiceReferences(filter);
+ ObjectName[] names = new ObjectName[refs.length];
+ for (int i = 0; i < refs.length; i++) {
+ names[i] = getComponentObjectName(refs[i]);
+ }
+ return names;
+ }
+
+ public String getSystemInfo() {
+ return "ServiceMix 4";
+ }
+
+ public ObjectName getSystemService(String serviceName) {
+ return null;
+ }
+
+ public ObjectName[] getSystemServices() {
+ return new ObjectName[0];
+ }
+
+ public boolean isBinding(String componentName) {
+ String filter = "(" + Deployer.NAME + "=" + componentName + ")";
+ ServiceReference ref = getComponentServiceReference(filter);
+ return "binding-component".equals(ref.getProperty(Deployer.TYPE));
+ }
+
+ public boolean isEngine(String componentName) {
+ String filter = "(" + Deployer.NAME + "=" + componentName + ")";
+ ServiceReference ref = getComponentServiceReference(filter);
+ return "service-engine".equals(ref.getProperty(Deployer.TYPE));
+ }
+}
Propchange: servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/AdminService.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/AdminService.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/DefaultNamingStrategy.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/DefaultNamingStrategy.java?rev=741047&r1=741046&r2=741047&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/DefaultNamingStrategy.java (original)
+++ servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/DefaultNamingStrategy.java Thu Feb 5 08:43:01 2009
@@ -16,9 +16,14 @@
*/
package org.apache.servicemix.jbi.management;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
import javax.management.ObjectName;
import javax.management.MalformedObjectNameException;
+import org.apache.servicemix.jbi.runtime.impl.ManagementContext;
+
/**
*/
public class DefaultNamingStrategy implements NamingStrategy {
@@ -52,6 +57,13 @@
"Type=ServiceAssembly," +
"Name=" + sanitize(serviceAssembly.getName()));
}
+
+ public ObjectName getObjectName(AdminCommandsServiceMBean adminCommandsService) throws MalformedObjectNameException {
+ return new ObjectName(jmxDomainName + ":" +
+ "Type=SystemService," +
+ "Name=AdminCommandsService");
+ }
+
private String sanitize(String in) {
String result = null;
@@ -65,6 +77,17 @@
}
return result;
}
+
+ public ObjectName createCustomComponentMBeanName(String type, String name) {
+ Map<String, String> result = new LinkedHashMap<String, String>();
+ result.put("Type", "Component");
+ result.put("Name", sanitize(name));
+ result.put("SubType", sanitize(type));
+ return createObjectName(result);
+ }
+ public ObjectName createObjectName(Map<String, String> props) {
+ return ManagementContext.createObjectName(getJmxDomainName(), props);
+ }
}
Added: servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/DeploymentService.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/DeploymentService.java?rev=741047&view=auto
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/DeploymentService.java (added)
+++ servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/DeploymentService.java Thu Feb 5 08:43:01 2009
@@ -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.servicemix.jbi.management;
+
+import javax.jbi.management.DeploymentServiceMBean;
+
+public class DeploymentService implements DeploymentServiceMBean {
+
+ public String deploy(String saZipURL) throws Exception {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public String undeploy(String saName) throws Exception {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public String[] getDeployedServiceUnitList(String componentName) throws Exception {
+ return new String[0]; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public String[] getDeployedServiceAssemblies() throws Exception {
+ return new String[0]; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public String getServiceAssemblyDescriptor(String saName) throws Exception {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public String[] getDeployedServiceAssembliesForComponent(String componentName) throws Exception {
+ return new String[0]; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public String[] getComponentsForDeployedServiceAssembly(String saName) throws Exception {
+ return new String[0]; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public boolean isDeployedServiceUnit(String componentName, String suName) throws Exception {
+ return false; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public boolean canDeployToComponent(String componentName) {
+ return false; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public String start(String serviceAssemblyName) throws Exception {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public String stop(String serviceAssemblyName) throws Exception {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public String shutDown(String serviceAssemblyName) throws Exception {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public String getState(String serviceAssemblyName) throws Exception {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+}
Propchange: servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/DeploymentService.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/DeploymentService.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/InstallationContextImpl.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/InstallationContextImpl.java?rev=741047&view=auto
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/InstallationContextImpl.java (added)
+++ servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/InstallationContextImpl.java Thu Feb 5 08:43:01 2009
@@ -0,0 +1,358 @@
+/*
+ * 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.servicemix.jbi.management;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.MissingResourceException;
+import java.util.logging.Logger;
+
+import javax.jbi.JBIException;
+import javax.jbi.component.ComponentContext;
+import javax.jbi.component.InstallationContext;
+import javax.jbi.management.MBeanNames;
+import javax.jbi.messaging.DeliveryChannel;
+import javax.jbi.messaging.MessagingException;
+import javax.jbi.servicedesc.ServiceEndpoint;
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+import javax.naming.InitialContext;
+import javax.xml.namespace.QName;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.DocumentFragment;
+
+import org.apache.servicemix.jbi.deployer.descriptor.ComponentDesc;
+import org.apache.servicemix.jbi.deployer.descriptor.InstallationDescriptorExtension;
+import org.apache.servicemix.jbi.deployer.descriptor.SharedLibraryList;
+
+
+/**
+ * This context contains information necessary for a JBI component to perform its installation/uninstallation
+ * processing. This is provided to the init() method of the component {@link javax.jbi.component.Bootstrap}interface.
+ *
+ */
+public class InstallationContextImpl implements InstallationContext, ComponentContext, MBeanNames {
+
+ private ComponentDesc descriptor;
+ private NamingStrategy namingStrategy;
+ private ManagementAgent managementAgent;
+ private File installRoot;
+ private List<String> classPathElements = Collections.emptyList();
+ private boolean install = true;
+
+ public InstallationContextImpl(ComponentDesc descriptor, NamingStrategy namingStrategy,
+ ManagementAgent managementAgent) {
+ this.descriptor = descriptor;
+ this.namingStrategy = namingStrategy;
+ this.managementAgent = managementAgent;
+ if (descriptor.getComponentClassPath() != null
+ && descriptor.getComponentClassPath().getPathElements() != null
+ && descriptor.getComponentClassPath().getPathElements().length > 0) {
+ String[] elems = descriptor.getComponentClassPath().getPathElements();
+ for (int i = 0; i < elems.length; i++) {
+ if (File.separatorChar == '\\') {
+ elems[i] = elems[i].replace('/', '\\');
+ } else {
+ elems[i] = elems[i].replace('\\', '/');
+ }
+ }
+ setClassPathElements(Arrays.asList(elems));
+ }
+ }
+
+ /**
+ * @return the descriptor
+ */
+ public ComponentDesc getDescriptor() {
+ return descriptor;
+ }
+
+ /**
+ * @return the sharedLibraries
+ */
+ public String[] getSharedLibraries() {
+ return getSharedLibraries(descriptor.getSharedLibraries());
+ }
+
+ /**
+ * Get the name of the class that implements the {@link javax.jbi.component.Component}interface for this component. This must be the
+ * component class name given in the component's installation descriptor.
+ *
+ * @return the {@link javax.jbi.component.Component}implementation class name, which must be non-null and non-empty.
+ */
+ public String getComponentClassName() {
+ return descriptor.getComponentClassName();
+ }
+
+ /**
+ * Get a list of elements that comprise the class path for this component. Each element represents either a
+ * directory (containing class files) or a library file. All elements are reachable from the install root. These
+ * elements represent class path items that the component's execution-time component class loader uses, in search
+ * order. All path elements must use the file separator character appropriate to the system (i.e.,
+ * <code>File.separator</code>).
+ *
+ * @return a list of String objects, each of which contains a class path elements. The list must contain at least
+ * one class path element.
+ */
+ public List getClassPathElements() {
+ return classPathElements;
+ }
+
+ /**
+ * Get the unique name assigned to this component. This name must be assigned from the component's installation
+ * descriptor identification section.
+ *
+ * @return the unique component name, which must be non-null and non-empty.
+ */
+ public String getComponentName() {
+ return descriptor.getIdentification().getName();
+ }
+
+ /**
+ * Get the JBI context for this component. The following methods are valid to use on the context:
+ * <ul>
+ * <li>{@link ComponentContext#getMBeanNames()}</li>
+ * <li>{@link ComponentContext#getMBeanServer()}</li>
+ * <li>{@link ComponentContext#getNamingContext()}</li>
+ * <li>{@link ComponentContext#getTransactionManager()}</li>
+ * </ul>
+ * All other methods on the returned context must throw a <code>IllegalStateException</code> exception if invoked.
+ *
+ * @return the JBI context for this component, which must be non-null.
+ */
+ public ComponentContext getContext() {
+ return this;
+ }
+
+ /**
+ * Get the installation root directory full path name for this component. This path name must be formatted for the
+ * platform the JBI environment is running on.
+ *
+ * @return the installation root directory name, which must be non-null and non-empty.
+ */
+ public String getInstallRoot() {
+ return installRoot != null ? installRoot.getAbsolutePath() : ".";
+ }
+
+ /**
+ * Return a DOM document fragment representing the installation descriptor (jbi.xml) extension data for the
+ * component, if any.
+ * <p>
+ * The Installation Descriptor Extension data are located at the end of the <component> element of the
+ * installation descriptor.
+ *
+ * @return a DOM document fragment containing the installation descriptor (jbi.xml) extension data, or
+ * <code>null</code> if none is present in the descriptor.
+ */
+ public DocumentFragment getInstallationDescriptorExtension() {
+ InstallationDescriptorExtension desc = descriptor.getDescriptorExtension();
+ return desc != null ? desc.getDescriptorExtension() : null;
+ }
+
+ /**
+ * Returns <code>true</code> if this context was created in order to install a component into the JBI environment.
+ * Returns <code>false</code> if this context was created to uninstall a previously installed component.
+ * <p>
+ * This method is provided to allow {@link javax.jbi.component.Bootstrap}implementations to tailor their behaviour according to use
+ * case. For example, the {@link javax.jbi.component.Bootstrap#init(InstallationContext)}method implementation may create different
+ * types of extension MBeans, depending on the use case specified by this method.
+ *
+ * @return <code>true</code> if this context was created in order to install a component into the JBI environment;
+ * otherwise the context was created to uninstall an existing component.
+ */
+ public boolean isInstall() {
+ return install;
+ }
+
+ /**
+ * Set the list of elements that comprise the class path for this component. Each element represents either a
+ * directory (containing class files) or a library file. Elements are reached from the install root. These elements
+ * represent class path items that the component's execution-time component class loader uses, in search order. All
+ * file paths are relative to the install root of the component.
+ * <p>
+ * This method allows the component's bootstrap to alter the execution-time class path specified by the component's
+ * installation descriptor. The component configuration determined during installation can affect the class path
+ * needed by the component at execution-time. All path elements must use the file separator character appropriate to
+ * the system (i.e., <code>File.separator</code>.
+ *
+ * @param classPathElements a list of String objects, each of which contains a class path elements; the list must be
+ * non-null and contain at least one class path element.
+ * @exception IllegalArgumentException if the class path elements is null, empty, or if an individual element is
+ * ill-formed.
+ */
+ public final void setClassPathElements(List classPathElements) {
+ if (classPathElements == null) {
+ throw new IllegalArgumentException("classPathElements is null");
+ }
+ if (classPathElements.isEmpty()) {
+ throw new IllegalArgumentException("classPathElements is empty");
+ }
+ for (Iterator iter = classPathElements.iterator(); iter.hasNext();) {
+ Object obj = iter.next();
+ if (!(obj instanceof String)) {
+ throw new IllegalArgumentException("classPathElements must contain element of type String");
+ }
+ String element = (String) obj;
+ String sep = "\\".equals(File.separator) ? "/" : "\\";
+ int offset = element.indexOf(sep);
+ if (offset > -1) {
+ throw new IllegalArgumentException("classPathElements contains an invalid file separator '" + sep + "'");
+ }
+ File f = new File((String) element);
+ if (f.isAbsolute()) {
+ throw new IllegalArgumentException("classPathElements should not contain absolute paths");
+ }
+ }
+ this.classPathElements = new ArrayList<String>(classPathElements);
+ }
+
+ public ServiceEndpoint activateEndpoint(QName serviceName, String endpointName) throws JBIException {
+ throw new IllegalStateException("This operation is not available at installation time");
+ }
+
+ public void deactivateEndpoint(ServiceEndpoint endpoint) throws JBIException {
+ throw new IllegalStateException("This operation is not available at installation time");
+ }
+
+ public void registerExternalEndpoint(ServiceEndpoint externalEndpoint) throws JBIException {
+ throw new IllegalStateException("This operation is not available at installation time");
+ }
+
+ public void deregisterExternalEndpoint(ServiceEndpoint externalEndpoint) throws JBIException {
+ throw new IllegalStateException("This operation is not available at installation time");
+ }
+
+ public ServiceEndpoint resolveEndpointReference(DocumentFragment epr) {
+ throw new IllegalStateException("This operation is not available at installation time");
+ }
+
+ public DeliveryChannel getDeliveryChannel() throws MessagingException {
+ throw new IllegalStateException("This operation is not available at installation time");
+ }
+
+ public ServiceEndpoint getEndpoint(QName service, String name) {
+ throw new IllegalStateException("This operation is not available at installation time");
+ }
+
+ public Document getEndpointDescriptor(ServiceEndpoint endpoint) throws JBIException {
+ throw new IllegalStateException("This operation is not available at installation time");
+ }
+
+ public ServiceEndpoint[] getEndpoints(QName interfaceName) {
+ throw new IllegalStateException("This operation is not available at installation time");
+ }
+
+ public ServiceEndpoint[] getEndpointsForService(QName serviceName) {
+ throw new IllegalStateException("This operation is not available at installation time");
+ }
+
+ public ServiceEndpoint[] getExternalEndpoints(QName interfaceName) {
+ throw new IllegalStateException("This operation is not available at installation time");
+ }
+
+ public ServiceEndpoint[] getExternalEndpointsForService(QName serviceName) {
+ throw new IllegalStateException("This operation is not available at installation time");
+ }
+
+ public Logger getLogger(String suffix, String resourceBundleName) throws MissingResourceException, JBIException {
+ throw new IllegalStateException("This operation is not available at installation time");
+ }
+
+ public MBeanNames getMBeanNames() {
+ return this;
+ }
+
+ public String getWorkspaceRoot() {
+ throw new IllegalStateException("This operation is not available at installation time");
+ }
+
+ public ObjectName createCustomComponentMBeanName(String customName) {
+ if (namingStrategy != null) {
+ return namingStrategy.createCustomComponentMBeanName(customName, descriptor.getIdentification().getName());
+ }
+ return null;
+ }
+
+ public String getJmxDomainName() {
+ if (namingStrategy != null) {
+ return namingStrategy.getJmxDomainName();
+ }
+ return null;
+ }
+
+ /**
+ * @param install The install to set.
+ */
+ public void setInstall(boolean install) {
+ this.install = install;
+ }
+ /**
+ * @param installRoot The installRoot to set.
+ */
+ public void setInstallRoot(File installRoot) {
+ this.installRoot = installRoot;
+ }
+ /**
+ * @return Returns the binding.
+ */
+ public boolean isBinding() {
+ return descriptor.isBindingComponent();
+ }
+ /**
+ * @return Returns the engine.
+ */
+ public boolean isEngine() {
+ return descriptor.isServiceEngine();
+ }
+ /**
+ * @return Returns the componentDescription.
+ */
+ public String getComponentDescription() {
+ return descriptor.getIdentification().getDescription();
+ }
+
+ private static String[] getSharedLibraries(SharedLibraryList[] sharedLibraries) {
+ if (sharedLibraries == null || sharedLibraries.length == 0) {
+ return null;
+ }
+ String[] names = new String[sharedLibraries.length];
+ for (int i = 0; i < names.length; i++) {
+ names[i] = sharedLibraries[i].getName();
+ }
+ return names;
+ }
+
+ public MBeanServer getMBeanServer() {
+ return managementAgent.getMbeanServer();
+ }
+
+ public InitialContext getNamingContext() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Object getTransactionManager() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
Propchange: servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/InstallationContextImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/InstallationContextImpl.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/InstallationService.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/InstallationService.java?rev=741047&view=auto
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/InstallationService.java (added)
+++ servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/InstallationService.java Thu Feb 5 08:43:01 2009
@@ -0,0 +1,293 @@
+/*
+ * 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.servicemix.jbi.management;
+
+import java.io.File;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Properties;
+import java.util.concurrent.ConcurrentHashMap;
+
+import javax.jbi.JBIException;
+import javax.jbi.management.DeploymentException;
+import javax.jbi.management.InstallationServiceMBean;
+import javax.management.Attribute;
+import javax.management.JMException;
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.servicemix.jbi.deployer.descriptor.Descriptor;
+import org.apache.servicemix.jbi.deployer.handler.Transformer;
+
+public class InstallationService implements InstallationServiceMBean {
+
+ private static final Log LOG = LogFactory.getLog(InstallationService.class);
+
+ private Map<String, Installer> installers = new ConcurrentHashMap<String, Installer>();
+
+ private Map<String, Installer> nonLoadedInstallers = new ConcurrentHashMap<String, Installer>();
+
+ private AdminService adminService;
+
+ private NamingStrategy namingStrategy;
+ private ManagementAgent managementAgent;
+
+ /**
+ * Load the installer for a new component from a component installation
+ * package.
+ *
+ * @param installJarURL -
+ * URL locating a jar file containing a JBI Installable
+ * Component.
+ * @return - the JMX ObjectName of the InstallerMBean loaded from
+ * installJarURL.
+ */
+ public synchronized ObjectName loadNewInstaller(String installJarURL) {
+ try {
+ ObjectName result = null;
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Loading new installer from " + installJarURL);
+ }
+ File jarfile = new File(installJarURL);
+ if (jarfile.exists()) {
+ Descriptor desc = Transformer.getDescriptor(jarfile);
+ if (desc != null && desc.getComponent() != null) {
+ String componentName = desc.getComponent().getIdentification().getName();
+ if (!installers.containsKey(componentName)) {
+ Installer installer = doInstallArchive(desc, jarfile);
+ if (installer != null) {
+ result = installer.getObjectName();
+ installers.put(componentName, installer);
+ }
+ } else {
+ throw new RuntimeException("An installer already exists for " + componentName);
+ }
+ } else {
+ throw new RuntimeException("Could not find Component from: " + installJarURL);
+ }
+ } else {
+ throw new RuntimeException("location: " + installJarURL + " isn't valid");
+ }
+ return result;
+ } catch (Throwable t) {
+ LOG.error("Deployment failed", t);
+ if (t instanceof Error) {
+ throw (Error) t;
+ }
+ if (t instanceof RuntimeException) {
+ throw (RuntimeException) t;
+ } else {
+ throw new RuntimeException("Deployment failed: " + t.getMessage());
+ }
+ }
+ }
+
+ private Installer doInstallArchive(Descriptor desc, File jarfile) throws Exception {
+ return new Installer(new InstallationContextImpl(desc.getComponent(), getNamingStrategy(), getManagementAgent()),
+ jarfile, getAdminService());
+ }
+
+ /**
+ * Load the InstallerMBean for a previously installed component.
+ *
+ * @param aComponentName -
+ * the component name identifying the installer to load.
+ * @return - the JMX ObjectName of the InstallerMBean loaded from an
+ * existing installation context.
+ */
+ public ObjectName loadInstaller(String aComponentName) {
+ Installer installer = installers.get(aComponentName);
+ if (installer == null) {
+ installer = nonLoadedInstallers.get(aComponentName);
+ if (installer != null) {
+ try {
+ // create an MBean for the installer
+ ObjectName objectName = getNamingStrategy().createCustomComponentMBeanName("Installer", aComponentName);
+ installer.setObjectName(objectName);
+ getManagementAgent().register(installer, objectName);
+ } catch (Exception e) {
+ throw new RuntimeException("Could not load installer", e);
+ }
+ return installer.getObjectName();
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Unload a JBI Installable Component installer.
+ *
+ * @param componentName -
+ * the component name identifying the installer to unload.
+ * @param isToBeDeleted -
+ * true if the component is to be deleted as well.
+ * @return - true if the operation was successful, otherwise false.
+ */
+ public boolean unloadInstaller(String componentName, boolean isToBeDeleted) {
+ boolean result = false;
+ try {
+ Installer installer = installers.remove(componentName);
+ result = installer != null;
+ if (result) {
+ getManagementAgent().unregister(installer.getObjectName());
+ if (isToBeDeleted) {
+ installer.uninstall();
+ } else {
+ nonLoadedInstallers.put(componentName, installer);
+ }
+ }
+ } catch (Exception e) {
+ String errStr = "Problem shutting down Component: " + componentName;
+ LOG.error(errStr, e);
+ } finally {
+ }
+ return result;
+ }
+
+ /**
+ * Install a shared library jar.
+ *
+ * @param aSharedLibURI -
+ * URI locating a jar file containing a shared library.
+ * @return - the name of the shared library loaded from aSharedLibURI.
+ */
+ public String installSharedLibrary(String aSharedLibURI) {
+ return ManagementSupport.createSuccessMessage("to be done");
+ }
+
+ /**
+ * Uninstall a shared library.
+ *
+ * @param aSharedLibName -
+ * the name of the shared library to uninstall.
+ * @return - true iff the uninstall was successful.
+ */
+ public boolean uninstallSharedLibrary(String aSharedLibName) {
+ // TODO
+ return false;
+
+ }
+
+ /**
+ * Install an archive
+ *
+ * @param location
+ * @param props
+ * @param autoStart
+ * @throws DeploymentException
+ */
+ public void install(String location, Properties props, boolean autoStart) throws DeploymentException {
+ File jarfile = new File(location);
+ if (jarfile.exists()) {
+ Descriptor desc = null;
+ try {
+ desc = Transformer.getDescriptor(jarfile);
+ } catch (Exception e) {
+ LOG.error("install component failed", e);
+ throw new DeploymentException("install component failed", e);
+ }
+ if (desc != null) {
+ if (desc.getComponent() == null) {
+ throw new DeploymentException("JBI descriptor is not a component descriptor");
+ }
+ install(jarfile, props, desc, autoStart);
+ } else {
+ throw new DeploymentException("Could not find JBI descriptor");
+ }
+ } else {
+ throw new DeploymentException("Could not find JBI descriptor");
+ }
+ }
+
+ /**
+ * Install an archive
+ *
+ * @param tmpDir
+ * @param root
+ * @param autoStart
+ * @throws DeploymentException
+ */
+ protected void install(File jarfile, Properties props, Descriptor desc, boolean autoStart) throws DeploymentException {
+ if (desc.getComponent() != null) {
+ String componentName = desc.getComponent().getIdentification().getName();
+ if (installers.containsKey(componentName)) {
+ throw new DeploymentException("Component " + componentName + " is already installed");
+ }
+ Installer installer = null;
+ try {
+ installer = doInstallArchive(desc, jarfile);
+ } catch (Exception e1) {
+ LOG.error("create installer for component " + desc.getComponent().getIdentification().getName()
+ + " failed", e1);
+ throw new DeploymentException("create installer for component " + desc.getComponent().getIdentification().getName()
+ + " failed", e1);
+ }
+ if (installer != null) {
+ try {
+ if (props != null && props.size() > 0) {
+ ObjectName on = installer.getInstallerConfigurationMBean();
+ if (on == null) {
+ LOG.warn("Could not find installation configuration MBean. Installation properties will be ignored.");
+ } else {
+ MBeanServer mbs = getManagementAgent().getMbeanServer();
+ for (Iterator it = props.keySet().iterator(); it.hasNext();) {
+ String key = (String) it.next();
+ String val = props.getProperty(key);
+ try {
+ mbs.setAttribute(on, new Attribute(key, val));
+ } catch (JMException e) {
+ throw new DeploymentException("Could not set installation property: (" + key + " = " + val, e);
+ }
+ }
+ }
+ }
+ installer.install();
+ } catch (JBIException e) {
+ throw new DeploymentException(e);
+ }
+ installers.put(componentName, installer);
+ }
+ }
+ }
+
+ public void setAdminService(AdminService adminService) {
+ this.adminService = adminService;
+ }
+
+ public AdminService getAdminService() {
+ return adminService;
+ }
+
+ public void setNamingStrategy(NamingStrategy namingStrategy) {
+ this.namingStrategy = namingStrategy;
+ }
+
+ public NamingStrategy getNamingStrategy() {
+ return namingStrategy;
+ }
+
+ public void setManagementAgent(ManagementAgent managementAgent) {
+ this.managementAgent = managementAgent;
+ }
+
+ public ManagementAgent getManagementAgent() {
+ return managementAgent;
+ }
+
+}
Propchange: servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/InstallationService.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/InstallationService.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/Installer.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/Installer.java?rev=741047&view=auto
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/Installer.java (added)
+++ servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/Installer.java Thu Feb 5 08:43:01 2009
@@ -0,0 +1,316 @@
+/*
+ * 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.servicemix.jbi.management;
+
+
+import java.io.Closeable;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.jar.Attributes;
+import java.util.jar.JarFile;
+import java.util.jar.Manifest;
+
+import javax.jbi.JBIException;
+import javax.jbi.management.DeploymentException;
+import javax.jbi.management.InstallerMBean;
+import javax.management.ObjectName;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.servicemix.kernel.filemonitor.DeploymentListener;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.ServiceReference;
+import org.springframework.osgi.context.BundleContextAware;
+
+public class Installer implements InstallerMBean, BundleContextAware {
+
+ private static final Log LOGGER = LogFactory.getLog(Installer.class);
+
+
+ private InstallationContextImpl context;
+ private File jbiArtifact;
+ private ObjectName objectName;
+ private BundleContext bundleContext;
+ private AdminService adminService;
+ private Bundle bundle;
+
+ private Map<String, String> artifactToBundle = new HashMap<String, String>();
+
+ public Installer(InstallationContextImpl ic, File jbiArtifact, AdminService adminService) throws DeploymentException {
+ this.context = ic;
+ this.jbiArtifact = jbiArtifact;
+ this.adminService = adminService;
+ setBundleContext(this.adminService.getBundleContext());
+ }
+
+ /**
+ * Get the installation root directory path for this BC or SE.
+ *
+ * @return the full installation path of this component.
+ */
+ public String getInstallRoot() {
+ return context.getInstallRoot();
+ }
+
+ /**
+ * Install a BC or SE.
+ *
+ * @return JMX ObjectName representing the ComponentLifeCycle for the installed component, or null if the
+ * installation did not complete.
+ * @throws javax.jbi.JBIException if the installation fails.
+ */
+ public ObjectName install() throws JBIException {
+
+ try {
+ if (isInstalled()) {
+ throw new DeploymentException("Component is already installed");
+ }
+ File f = transformArtifact(jbiArtifact);
+ if (f == null) {
+ LOGGER.info("Unsupported deployment: " + f.getName());
+ return null;
+ }
+ if (f.exists()) {
+ deployBundle(f);
+ }
+ context.setInstall(false);
+ ObjectName ret = this.adminService.getComponentByName(context.getComponentName());
+ return ret;
+ } catch (Exception e) {
+ LOGGER.error(e.getMessage());
+ throw new JBIException(e);
+ }
+
+ }
+
+
+ /**
+ * Determine whether or not the component is installed.
+ *
+ * @return true if this component is currently installed, false if not.
+ */
+ public boolean isInstalled() {
+ return !context.isInstall();
+ }
+
+ /**
+ * Uninstall a BC or SE. This completely removes the component from the JBI system.
+ *
+ * @throws javax.jbi.JBIException if the uninstallation fails.
+ */
+ public void uninstall() throws javax.jbi.JBIException {
+ // TODO: check component status
+ // the component must not be started and not have any SUs deployed
+ if (!isInstalled()) {
+ throw new DeploymentException("Component is not installed");
+ }
+ String componentName = context.getComponentName();
+ try {
+ Bundle bundle = getBundle();
+
+ if (bundle == null) {
+ LOGGER.warn("Could not find Bundle for component: " + componentName);
+ }
+ else {
+ bundle.stop();
+ bundle.uninstall();
+ }
+ } catch (BundleException e) {
+ LOGGER.error("failed to uninstall component: " + componentName, e);
+ throw new JBIException(e);
+ }
+ }
+
+ /**
+ * Get the installer configuration MBean name for this component.
+ *
+ * @return the MBean object name of the Installer Configuration MBean.
+ * @throws javax.jbi.JBIException if the component is not in the LOADED state or any error occurs during processing.
+ */
+ public ObjectName getInstallerConfigurationMBean() throws javax.jbi.JBIException {
+ //TODO
+ return null;
+ }
+ /**
+ * @return Returns the objectName.
+ */
+ public ObjectName getObjectName() {
+ return objectName;
+ }
+ /**
+ * @param objectName The objectName to set.
+ */
+ public void setObjectName(ObjectName objectName) {
+ this.objectName = objectName;
+ }
+
+ public synchronized void deployFile(String filename) {
+ File file = new File(filename);
+ try {
+ LOGGER.info("File is: " + filename);
+ // Transformation step
+ if (file.exists()) {
+ LOGGER.info("File exist");
+ File f = transformArtifact(file);
+ if (f == null) {
+ LOGGER.info("Unsupported deployment: " + filename);
+ return;
+ }
+ file = f;
+ } else {
+ String transformedFile = artifactToBundle.get(filename);
+ if (transformedFile != null) {
+ file = new File(transformedFile);
+ if (file.exists()) {
+ file.delete();
+ }
+ }
+ }
+
+ // Handle final bundles
+ if (file.exists()) {
+ deployBundle(file);
+ }
+
+ } catch (Exception e) {
+ LOGGER.info("Failed to process: " + file + ". Reason: " + e, e);
+ }
+
+ }
+
+ protected Bundle getBundleForJarFile(File file) throws IOException {
+ String absoluteFilePath = file.getAbsoluteFile().toURI().toString();
+ Bundle bundles[] = bundleContext.getBundles();
+ for (Bundle bundle : bundles) {
+ String location = bundle.getLocation();
+ if (filePathsMatch(absoluteFilePath, location)) {
+ return bundle;
+ }
+ }
+ return null;
+ }
+
+ protected static boolean filePathsMatch(String p1, String p2) {
+ p1 = normalizeFilePath(p1);
+ p2 = normalizeFilePath(p2);
+ return (p1 != null && p1.equalsIgnoreCase(p2));
+ }
+
+ protected static String normalizeFilePath( String path ) {
+ if (path != null) {
+ path = path.replaceFirst("file:/*", "");
+ path = path.replaceAll("[\\\\/]+", "/");
+ }
+ return path;
+ }
+
+
+ protected void deployBundle(File file) throws IOException, BundleException {
+ LOGGER.info("Deploying: " + file.getCanonicalPath());
+
+ InputStream in = new FileInputStream(file);
+
+ try {
+ Bundle bundle = getBundleForJarFile(file);
+ if (bundle != null) {
+ bundle.update();
+ }
+ else {
+ bundle = bundleContext.installBundle(file.getCanonicalFile().toURI().toString(), in);
+ bundle.start();
+ }
+ setBundle(bundle);
+ }
+ finally {
+ closeQuietly(in);
+ }
+ }
+
+ protected void closeQuietly(Closeable in) {
+ try {
+ in.close();
+ }
+ catch (IOException e) {
+ LOGGER.info("Failed to close stream. " + e, e);
+ }
+ }
+
+ public File getGenerateDir() {
+ String base = System.getProperty("servicemix.base", ".");
+ return new File(base, "data/generated-bundles");
+ }
+
+ private File transformArtifact(File file) throws Exception {
+ // Check registered deployers
+ ServiceReference[] srvRefs = bundleContext.getAllServiceReferences(DeploymentListener.class.getName(), null);
+ if(srvRefs != null) {
+ for(ServiceReference sr : srvRefs) {
+ try {
+ DeploymentListener deploymentListener = (DeploymentListener) bundleContext.getService(sr);
+ if (deploymentListener.canHandle(file)) {
+ File transformedFile = deploymentListener.handle(file, getGenerateDir());
+ artifactToBundle.put(file.getAbsolutePath(), transformedFile.getAbsolutePath());
+ return transformedFile;
+ }
+ } finally {
+ bundleContext.ungetService(sr);
+ }
+ }
+ }
+ JarFile jar = null;
+ try {
+ // Handle OSGi bundles with the default deployer
+ if (file.getName().endsWith("txt") || file.getName().endsWith("xml")
+ || file.getName().endsWith("properties")) {
+ // that's file type which is not supported as bundle and avoid exception in the log
+ return null;
+ }
+ jar = new JarFile(file);
+ Manifest m = jar.getManifest();
+ if (m.getMainAttributes().getValue(new Attributes.Name("Bundle-SymbolicName")) != null &&
+ m.getMainAttributes().getValue(new Attributes.Name("Bundle-Version")) != null) {
+ return file;
+ }
+ } catch (Exception e) {
+ LOGGER.info("Error transforming artifact " + file.getName(), e);
+ } finally {
+ if (jar != null) {
+ jar.close();
+ }
+ }
+ return null;
+ }
+
+ public void setBundleContext(BundleContext bundleContext) {
+ this.bundleContext = bundleContext;
+ }
+
+ public void setBundle(Bundle bundle) {
+ this.bundle = bundle;
+ }
+
+ public Bundle getBundle() {
+ return bundle;
+ }
+
+}
Propchange: servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/Installer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/Installer.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/ManagedJbiRegistry.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/ManagedJbiRegistry.java?rev=741047&r1=741046&r2=741047&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/ManagedJbiRegistry.java (original)
+++ servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/ManagedJbiRegistry.java Thu Feb 5 08:43:01 2009
@@ -34,6 +34,8 @@
private NamingStrategy namingStrategy;
private ManagementAgent managementAgent;
+ private AdminCommandsService adminCommandsService;
+ private AdminService adminService;
private Map<String, ManagedSharedLibrary> sharedLibraries;
private Map<String, ManagedComponent> components;
private Map<String, ManagedServiceAssembly> serviceAssemblies;
@@ -52,7 +54,23 @@
this.namingStrategy = namingStrategy;
}
- public ManagementAgent getManagementAgent() {
+ public void setAdminService(AdminService adminService) {
+ this.adminService = adminService;
+ }
+
+ public AdminService getAdminService() {
+ return adminService;
+ }
+
+ public void setAdminCommandsService(AdminCommandsService adminCommandsService) {
+ this.adminCommandsService = adminCommandsService;
+ }
+
+ public AdminCommandsService getAdminCommandsService() {
+ return adminCommandsService;
+ }
+
+ public ManagementAgent getManagementAgent() {
return managementAgent;
}
@@ -130,7 +148,12 @@
if (namingStrategy == null) {
throw new IllegalArgumentException("namingStrategy must not be null");
}
+
+ if (adminCommandsService == null) {
+ throw new IllegalArgumentException("adminCommandsService must not be null");
+ }
+ managementAgent.register(adminCommandsService, namingStrategy.getObjectName(adminCommandsService));
}
}
Added: servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/ManagementSupport.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/ManagementSupport.java?rev=741047&view=auto
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/ManagementSupport.java (added)
+++ servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/ManagementSupport.java Thu Feb 5 08:43:01 2009
@@ -0,0 +1,288 @@
+/*
+ * 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.servicemix.jbi.management;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.jbi.management.DeploymentException;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.servicemix.jbi.runtime.impl.utils.DOMUtil;
+
+/**
+ * ManagementMessageHelper is a class that ease the building of management messages.
+ */
+public final class ManagementSupport {
+
+ private static final Log LOG = LogFactory.getLog(ManagementSupport.class);
+
+ private ManagementSupport() {
+ }
+
+ public static class Message {
+ private boolean isCauseFramework;
+ private String task;
+ private String result;
+ private Exception exception;
+ private String type;
+ private String message;
+ private String component;
+ private String locale;
+
+ public Exception getException() {
+ return exception;
+ }
+ public void setException(Exception exception) {
+ this.exception = exception;
+ }
+ public boolean isCauseFramework() {
+ return isCauseFramework;
+ }
+ public void setCauseFramework(boolean value) {
+ this.isCauseFramework = value;
+ }
+ public String getMessage() {
+ return message;
+ }
+ public void setMessage(String message) {
+ this.message = message;
+ }
+ public String getResult() {
+ return result;
+ }
+ public void setResult(String result) {
+ this.result = result;
+ }
+ public String getTask() {
+ return task;
+ }
+ public void setTask(String task) {
+ this.task = task;
+ }
+ public String getType() {
+ return type;
+ }
+ public void setType(String type) {
+ this.type = type;
+ }
+ public String getComponent() {
+ return component;
+ }
+ public void setComponent(String component) {
+ this.component = component;
+ }
+ public String getLocale() {
+ return locale;
+ }
+ public void setLocale(String locale) {
+ this.locale = locale;
+ }
+ }
+
+ public static Exception failure(String task, String info) throws Exception {
+ return failure(task, info, null, null);
+ }
+
+ public static Exception failure(String task, List componentResults) throws Exception {
+ return failure(task, null, null, componentResults);
+ }
+
+ public static Exception failure(String task, String info, Exception e) throws Exception {
+ return failure(task, info, e, null);
+ }
+
+ public static Exception failure(String task, String info, Exception e, List componentResults) throws Exception {
+ ManagementSupport.Message msg = new ManagementSupport.Message();
+ msg.setTask(task);
+ msg.setResult("FAILED");
+ msg.setType("ERROR");
+ msg.setException(e);
+ msg.setMessage(info);
+ return new Exception(ManagementSupport.createFrameworkMessage(msg, componentResults));
+ }
+
+ public static String createSuccessMessage(String task) {
+ return createSuccessMessage(task, null, null);
+ }
+
+ public static String createSuccessMessage(String task, List componentResults) {
+ return createSuccessMessage(task, null, componentResults);
+ }
+
+ public static String createSuccessMessage(String task, String info) {
+ return createSuccessMessage(task, info, null);
+ }
+
+ public static String createSuccessMessage(String task, String info, List componentResults) {
+ ManagementSupport.Message msg = new ManagementSupport.Message();
+ msg.setTask(task);
+ msg.setResult("SUCCESS");
+ msg.setMessage(info);
+ return ManagementSupport.createFrameworkMessage(msg, componentResults);
+ }
+
+ public static String createWarningMessage(String task, String info, List componentResults) {
+ ManagementSupport.Message msg = new ManagementSupport.Message();
+ msg.setTask(task);
+ msg.setResult("SUCCESS");
+ msg.setType("WARNING");
+ msg.setMessage(info);
+ return ManagementSupport.createFrameworkMessage(msg, componentResults);
+ }
+
+ public static String createFrameworkMessage(Message fmkMsg, List componentResults) {
+ try {
+ Document doc = createDocument();
+ Element jbiTask = createChild(doc, "jbi-task");
+ jbiTask.setAttribute("xmlns", "http://java.sun.com/xml/ns/jbi/management-message");
+ jbiTask.setAttribute("version", "1.0");
+ Element jbiTaskResult = createChild(jbiTask, "jbi-task-result");
+ Element frmkTaskResult = createChild(jbiTaskResult, "frmwk-task-result");
+ Element frmkTaskResultDetails = createChild(frmkTaskResult, "frmwk-task-result-details");
+ appendTaskResultDetails(frmkTaskResultDetails, fmkMsg);
+ if (fmkMsg.getLocale() != null) {
+ createChild(frmkTaskResult, "locale", fmkMsg.getLocale());
+ }
+ if (componentResults != null) {
+ for (Iterator iter = componentResults.iterator(); iter.hasNext();) {
+ Element element = (Element) iter.next();
+ jbiTaskResult.appendChild(doc.importNode(element, true));
+ }
+ }
+ return DOMUtil.asIndentedXML(doc);
+ } catch (Exception e) {
+ LOG.error("Error", e);
+ return null;
+ }
+ }
+
+ private static Document createDocument() {
+ try {
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ factory.setNamespaceAware(true);
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ return builder.newDocument();
+ } catch (Exception e) {
+ throw new RuntimeException("Could not create DOM document", e);
+ }
+ }
+
+ private static Element createChild(Node parent, String name) {
+ return createChild(parent, name, null);
+ }
+
+ private static Element createChild(Node parent, String name, String text) {
+ Document doc = parent instanceof Document ? (Document) parent : parent.getOwnerDocument();
+ Element child = doc.createElementNS("http://java.sun.com/xml/ns/jbi/management-message", name);
+ if (text != null) {
+ child.appendChild(doc.createTextNode(text));
+ }
+ parent.appendChild(child);
+ return child;
+ }
+
+ private static void appendTaskResultDetails(Element root, Message fmkMsg) {
+ Element taskResultDetails = createChild(root, "task-result-details");
+ createChild(taskResultDetails, "task-id", fmkMsg.getTask());
+ createChild(taskResultDetails, "task-result", fmkMsg.getResult());
+ if (fmkMsg.getType() != null) {
+ createChild(taskResultDetails, "message-type", fmkMsg.getType());
+ }
+ // task-status-message
+ if (fmkMsg.getMessage() != null) {
+ Element taskStatusMessage = createChild(taskResultDetails, "task-status-msg");
+ Element msgLocInfo = createChild(taskStatusMessage, "msg-loc-info");
+ createChild(msgLocInfo, "loc-token");
+ createChild(msgLocInfo, "loc-message", fmkMsg.getMessage());
+ }
+ // exception-info
+ if (fmkMsg.getException() != null) {
+ Element exceptionInfo = createChild(taskResultDetails, "exception-info");
+ createChild(exceptionInfo, "nesting-level", "1");
+ createChild(exceptionInfo, "loc-token");
+ createChild(exceptionInfo, "loc-message", fmkMsg.getException().getMessage());
+ Element stackTrace = createChild(exceptionInfo, "stack-trace");
+ StringWriter sw2 = new StringWriter();
+ PrintWriter pw = new PrintWriter(sw2);
+ fmkMsg.getException().printStackTrace(pw);
+ pw.close();
+ stackTrace.appendChild(root.getOwnerDocument().createCDATASection(sw2.toString()));
+ }
+ }
+
+ public static DeploymentException componentFailure(String task, String component, String info) {
+ try {
+ Element e = createComponentFailure(task, component, info, null);
+ return new DeploymentException(DOMUtil.asXML(e));
+ } catch (Exception e) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Error creating management message", e);
+ }
+ return new DeploymentException(info);
+ }
+ }
+
+ public static Element createComponentMessage(Message msg) {
+ Document doc = createDocument();
+ Element componentTaskResult = createChild(doc, "component-task-result");
+ createChild(componentTaskResult, "component-name", msg.getComponent());
+ Element componentTaskResultDetails = createChild(componentTaskResult, "component-task-result-details");
+ appendTaskResultDetails(componentTaskResultDetails, msg);
+ return componentTaskResult;
+ }
+
+ public static Element createComponentSuccess(String task, String component) {
+ ManagementSupport.Message msg = new ManagementSupport.Message();
+ msg.setTask(task);
+ msg.setResult("SUCCESS");
+ msg.setComponent(component);
+ return createComponentMessage(msg);
+ }
+
+ public static Element createComponentFailure(String task, String component, String info, Exception e) {
+ ManagementSupport.Message msg = new ManagementSupport.Message();
+ msg.setTask(task);
+ msg.setResult("FAILED");
+ msg.setType("ERROR");
+ msg.setException(e);
+ msg.setMessage(info);
+ msg.setComponent(component);
+ return createComponentMessage(msg);
+ }
+
+ public static Element createComponentWarning(String task, String component, String info, Exception e) {
+ ManagementSupport.Message msg = new ManagementSupport.Message();
+ msg.setTask(task);
+ msg.setResult("SUCCESS");
+ msg.setType("WARNING");
+ msg.setException(e);
+ msg.setMessage(info);
+ msg.setComponent(component);
+ return createComponentMessage(msg);
+ }
+
+}
Propchange: servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/ManagementSupport.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/ManagementSupport.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/NamingStrategy.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/NamingStrategy.java?rev=741047&r1=741046&r2=741047&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/NamingStrategy.java (original)
+++ servicemix/smx4/nmr/trunk/jbi/management/src/main/java/org/apache/servicemix/jbi/management/NamingStrategy.java Thu Feb 5 08:43:01 2009
@@ -28,5 +28,10 @@
ObjectName getObjectName(ManagedComponent component) throws MalformedObjectNameException;
ObjectName getObjectName(ManagedServiceAssembly serviceAssembly) throws MalformedObjectNameException;
-
+
+ ObjectName getObjectName(AdminCommandsServiceMBean adminCommandsService) throws MalformedObjectNameException;
+
+ ObjectName createCustomComponentMBeanName(String type, String name);
+
+ String getJmxDomainName();
}