modules/core/client-api/src/main/java/org/rhq/core/clientapi/agent/bundle/BundleAgentService.java | 7 modules/core/client-api/src/main/java/org/rhq/core/clientapi/agent/bundle/BundleScheduleRequest.java | 56 +++++ modules/core/client-api/src/main/java/org/rhq/core/clientapi/agent/bundle/BundleScheduleResponse.java | 66 +++++ modules/core/client-api/src/main/java/org/rhq/core/clientapi/agent/bundle/BundleUpdateRequest.java | 31 -- modules/core/client-api/src/main/java/org/rhq/core/clientapi/agent/bundle/BundleUpdateResponse.java | 31 -- modules/core/client-api/src/main/java/org/rhq/core/clientapi/server/bundle/BundleServerService.java | 27 ++ modules/core/client-api/src/main/java/org/rhq/core/clientapi/server/bundle/BundleStatusUpdate.java | 33 ++ modules/core/client-api/src/main/java/org/rhq/core/clientapi/server/bundle/BundleUpdateComplete.java | 31 -- modules/core/plugin-api/src/main/java/org/rhq/core/pluginapi/bundle/BundleDeployRequest.java | 54 ++++ modules/core/plugin-api/src/main/java/org/rhq/core/pluginapi/bundle/BundleDeployResult.java | 64 +++++ modules/core/plugin-api/src/main/java/org/rhq/core/pluginapi/bundle/BundleFacet.java | 1 modules/core/plugin-container/src/main/java/org/rhq/core/pc/ServerServices.java | 57 +++-- modules/core/plugin-container/src/main/java/org/rhq/core/pc/bundle/BundleManager.java | 111 +++++++++- modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentMain.java | 3 modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/bundle/BundleManagerBean.java | 11 modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/bundle/BundleManagerLocal.java | 3 modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/bundle/BundleServerServiceImpl.java | 39 +++ modules/plugins/filetemplate-bundle/src/main/java/org/rhq/plugins/filetemplate/FileTemplateBundlePluginServerComponent.java | 9 18 files changed, 506 insertions(+), 128 deletions(-)
New commits: commit 632be079062b309fe0f9e02b9553c6eb5a91304b Author: John Mazzitelli mazz@redhat.com Date: Fri Feb 26 12:28:52 2010 -0500
API for agent plugin to ask for bundle file content
diff --git a/modules/core/client-api/src/main/java/org/rhq/core/clientapi/server/bundle/BundleServerService.java b/modules/core/client-api/src/main/java/org/rhq/core/clientapi/server/bundle/BundleServerService.java index eb09a4e..dbc0555 100644 --- a/modules/core/client-api/src/main/java/org/rhq/core/clientapi/server/bundle/BundleServerService.java +++ b/modules/core/client-api/src/main/java/org/rhq/core/clientapi/server/bundle/BundleServerService.java @@ -22,10 +22,14 @@ */ package org.rhq.core.clientapi.server.bundle;
+import java.io.OutputStream; import java.util.List;
+import org.rhq.core.clientapi.server.content.ContentServerService; import org.rhq.core.communications.command.annotation.Asynchronous; -import org.rhq.core.domain.bundle.BundleFile; +import org.rhq.core.communications.command.annotation.LimitedConcurrency; +import org.rhq.core.communications.command.annotation.Timeout; +import org.rhq.core.domain.content.PackageVersion;
/** * Interface for agents to use when needing to inform the server about bundle tasks. Implementations of this interface, once registered with the @@ -38,5 +42,21 @@ public interface BundleServerService { @Asynchronous(guaranteedDelivery = true) void updateStatus(BundleStatusUpdate update);
- List<BundleFile> getAllBundleFiles(int bundleVersionId); + List<PackageVersion> getAllBundleVersionPackageVersions(int bundleVersionId); + + /** + * Requests that the server download and stream the bits for the specified package version. + * If the package cannot be found, an exception will be thrown. + * + * @param packageVersion identifies the package to download + * @param outputStream an output stream where the server should write the package contents. It is up to the + * caller to prepare this output stream in order to write the package content to an + * appropriate location. + * + * @return the number of bytes written to the output stream - this is the size of the package version that was + * downloaded + */ + @Timeout(45 * 60 * 1000L) + @LimitedConcurrency(ContentServerService.CONCURRENCY_LIMIT_CONTENT_DOWNLOAD) + long downloadPackageBits(PackageVersion packageVersion, OutputStream outputStream); } \ No newline at end of file diff --git a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/bundle/BundleManager.java b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/bundle/BundleManager.java index 4ab1c03..abbef53 100644 --- a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/bundle/BundleManager.java +++ b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/bundle/BundleManager.java @@ -22,6 +22,7 @@ */ package org.rhq.core.pc.bundle;
+import java.io.OutputStream; import java.util.List; import java.util.Set;
@@ -34,9 +35,9 @@ import org.rhq.core.clientapi.agent.bundle.BundleScheduleRequest; import org.rhq.core.clientapi.agent.bundle.BundleScheduleResponse; import org.rhq.core.clientapi.server.bundle.BundleServerService; import org.rhq.core.domain.bundle.BundleDeployDefinition; -import org.rhq.core.domain.bundle.BundleFile; import org.rhq.core.domain.bundle.BundleType; import org.rhq.core.domain.bundle.BundleVersion; +import org.rhq.core.domain.content.PackageVersion; import org.rhq.core.domain.resource.Resource; import org.rhq.core.domain.resource.ResourceType; import org.rhq.core.pc.ContainerService; @@ -120,9 +121,24 @@ public class BundleManager extends AgentService implements BundleAgentService, C * @return the bundle files that are associated with the given bundle * @throws Exception */ - public List<BundleFile> getAllBundleFiles(BundleVersion bundleVersion) throws Exception { - List<BundleFile> bundleFiles = getBundleServerService().getAllBundleFiles(bundleVersion.getId()); - return bundleFiles; + public List<PackageVersion> getAllBundleVersionPackageVersions(BundleVersion bundleVersion) throws Exception { + int bvId = bundleVersion.getId(); + List<PackageVersion> pvs = getBundleServerService().getAllBundleVersionPackageVersions(bvId); + return pvs; + } + + /** + * This is used by bundle plugins - bundle plugins call back into this manager to obtain the + * bundle file content for the given package. + * + * @param packageVersion the package whose bits are to be downloaded + * @param outputStream where the package bits will get written to + * @return the size of the package version content that was downloaded and output + * @throws Exception + */ + public long getFileContent(PackageVersion packageVersion, OutputStream outputStream) throws Exception { + long size = getBundleServerService().downloadPackageBitsGivenResource(packageVersion, outputStream); + return size; }
/** diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/bundle/BundleManagerBean.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/bundle/BundleManagerBean.java index 747b980..ce559bf 100644 --- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/bundle/BundleManagerBean.java +++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/bundle/BundleManagerBean.java @@ -35,6 +35,7 @@ import org.rhq.core.domain.auth.Subject; import org.rhq.core.domain.bundle.Bundle; import org.rhq.core.domain.bundle.BundleDeployDefinition; import org.rhq.core.domain.bundle.BundleDeployment; +import org.rhq.core.domain.bundle.BundleFile; import org.rhq.core.domain.bundle.BundleType; import org.rhq.core.domain.bundle.BundleVersion; import org.rhq.core.domain.content.Repo; @@ -71,6 +72,14 @@ public class BundleManagerBean implements BundleManagerLocal, BundleManagerRemot @EJB private ResourceTypeManagerLocal resourceTypeManager;
+ @SuppressWarnings("unchecked") + public List<BundleFile> findBundleFilesForBundleVersion(int bundleVersionId) throws Exception { + Query q = entityManager.createNamedQuery(BundleFile.QUERY_FIND_BY_BUNDLE_VERSION_ID); + q.setParameter("id", bundleVersionId); + List<BundleFile> bundleFiles = (List<BundleFile>) q.getResultList(); + return bundleFiles; + } + public Bundle createBundle(Subject subject, Bundle bundle) { // add the implicit bundle repo, if necessary if (null == bundle.getRepo()) { @@ -80,6 +89,8 @@ public class BundleManagerBean implements BundleManagerLocal, BundleManagerRemot bundle.setRepo(repo); }
+ log.info("Creating bundle: " + bundle); + entityManager.persist(bundle); return bundle; } diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/bundle/BundleManagerLocal.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/bundle/BundleManagerLocal.java index 9cfc099..9266530 100644 --- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/bundle/BundleManagerLocal.java +++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/bundle/BundleManagerLocal.java @@ -26,6 +26,7 @@ import org.rhq.core.domain.auth.Subject; import org.rhq.core.domain.bundle.Bundle; import org.rhq.core.domain.bundle.BundleDeployDefinition; import org.rhq.core.domain.bundle.BundleDeployment; +import org.rhq.core.domain.bundle.BundleFile; import org.rhq.core.domain.bundle.BundleType; import org.rhq.core.domain.bundle.BundleVersion; import org.rhq.core.domain.criteria.BundleCriteria; @@ -47,6 +48,8 @@ public interface BundleManagerLocal {
BundleVersion createBundleVersion(Subject subject, BundleVersion bundleVersion);
+ List<BundleFile> findBundleFilesForBundleVersion(int bundleVersionId) throws Exception; + // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! // // The remaining methods are shared with the Remote Interface. diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/bundle/BundleServerServiceImpl.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/bundle/BundleServerServiceImpl.java index fa84821..09f4669 100644 --- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/bundle/BundleServerServiceImpl.java +++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/bundle/BundleServerServiceImpl.java @@ -18,6 +18,8 @@ */ package org.rhq.enterprise.server.bundle;
+import java.io.OutputStream; +import java.util.ArrayList; import java.util.List;
import org.apache.commons.logging.Log; @@ -26,6 +28,10 @@ import org.apache.commons.logging.LogFactory; import org.rhq.core.clientapi.server.bundle.BundleServerService; import org.rhq.core.clientapi.server.bundle.BundleStatusUpdate; import org.rhq.core.domain.bundle.BundleFile; +import org.rhq.core.domain.content.PackageVersion; +import org.rhq.core.util.exception.WrappedRemotingException; +import org.rhq.enterprise.server.content.ContentSourceManagerLocal; +import org.rhq.enterprise.server.util.LookupUtil;
/** * Server-side implementation of the <code>BundleServerService</code>. This implmentation simply forwards @@ -40,7 +46,29 @@ public class BundleServerServiceImpl implements BundleServerService { // TODO Auto-generated method stub }
- public List<BundleFile> getAllBundleFiles(int bundleVersionId) { - return null; + public List<PackageVersion> getAllBundleVersionPackageVersions(int bundleVersionId) { + try { + BundleManagerLocal bm = LookupUtil.getBundleManager(); + List<BundleFile> bundleFiles = bm.findBundleFilesForBundleVersion(bundleVersionId); + List<PackageVersion> packageVersions = new ArrayList<PackageVersion>(bundleFiles.size()); + for (BundleFile bundleFile : bundleFiles) { + packageVersions.add(bundleFile.getPackageVersion()); + } + return packageVersions; + } catch (Exception e) { + log.error("Failed to obtain bundle files for bundle version id: " + bundleVersionId, e); + throw new WrappedRemotingException(e); + } + } + + public long downloadPackageBits(PackageVersion packageVersion, OutputStream outputStream) { + try { + ContentSourceManagerLocal csm = LookupUtil.getContentSourceManager(); + long size = csm.outputPackageVersionBits(packageVersion, outputStream); + return size; + } catch (Exception e) { + log.error("Failed to obtain package version bits for package version: " + packageVersion, e); + throw new WrappedRemotingException(e); + } } } \ No newline at end of file
commit f96e2404b6596f030fdc1d4d54a6a4d0a6c8e36e Author: John Mazzitelli mazz@redhat.com Date: Fri Feb 26 10:20:49 2010 -0500
starting agent side bundle deployment stuff - not even close to useful yet
diff --git a/modules/core/client-api/src/main/java/org/rhq/core/clientapi/agent/bundle/BundleAgentService.java b/modules/core/client-api/src/main/java/org/rhq/core/clientapi/agent/bundle/BundleAgentService.java index 2e0f2f2..345567f 100644 --- a/modules/core/client-api/src/main/java/org/rhq/core/clientapi/agent/bundle/BundleAgentService.java +++ b/modules/core/client-api/src/main/java/org/rhq/core/clientapi/agent/bundle/BundleAgentService.java @@ -30,5 +30,10 @@ package org.rhq.core.clientapi.agent.bundle; * @author John Mazzitelli */ public interface BundleAgentService { - BundleUpdateResponse update(BundleUpdateRequest request); + /** + * Schedules the deployment of a bundle to occur immediately. + * @param request + * @return the results of the immediate scheduling + */ + BundleScheduleResponse schedule(BundleScheduleRequest request); } \ No newline at end of file diff --git a/modules/core/client-api/src/main/java/org/rhq/core/clientapi/agent/bundle/BundleScheduleRequest.java b/modules/core/client-api/src/main/java/org/rhq/core/clientapi/agent/bundle/BundleScheduleRequest.java new file mode 100644 index 0000000..0b49cd7 --- /dev/null +++ b/modules/core/client-api/src/main/java/org/rhq/core/clientapi/agent/bundle/BundleScheduleRequest.java @@ -0,0 +1,56 @@ +/* + * RHQ Management Platform + * Copyright (C) 2005-2008 Red Hat, Inc. + * All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License, version 2, as + * published by the Free Software Foundation, and/or the GNU Lesser + * General Public License, version 2.1, also as published by the Free + * Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License and the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License + * and the GNU Lesser General Public License along with this program; + * if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +package org.rhq.core.clientapi.agent.bundle; + +import java.io.Serializable; + +import org.rhq.core.domain.bundle.BundleDeployDefinition; + +/** + * @author John Mazzitelli + */ +public class BundleScheduleRequest implements Serializable { + private static final long serialVersionUID = 1L; + + private BundleDeployDefinition bundleDeployDefinition; + + public BundleScheduleRequest(BundleDeployDefinition bundleDef) { + this.bundleDeployDefinition = bundleDef; + } + + public BundleDeployDefinition getBundleDeployDefinition() { + return bundleDeployDefinition; + } + + public void setBundleDeployDefinition(BundleDeployDefinition bundleDeployDefinition) { + this.bundleDeployDefinition = bundleDeployDefinition; + } + + @Override + public String toString() { + StringBuilder str = new StringBuilder(this.getClass() + ": "); + str.append(bundleDeployDefinition.toString()); + return str.toString(); + } +} diff --git a/modules/core/client-api/src/main/java/org/rhq/core/clientapi/agent/bundle/BundleScheduleResponse.java b/modules/core/client-api/src/main/java/org/rhq/core/clientapi/agent/bundle/BundleScheduleResponse.java new file mode 100644 index 0000000..a82e866 --- /dev/null +++ b/modules/core/client-api/src/main/java/org/rhq/core/clientapi/agent/bundle/BundleScheduleResponse.java @@ -0,0 +1,66 @@ +/* + * RHQ Management Platform + * Copyright (C) 2005-2008 Red Hat, Inc. + * All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License, version 2, as + * published by the Free Software Foundation, and/or the GNU Lesser + * General Public License, version 2.1, also as published by the Free + * Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License and the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License + * and the GNU Lesser General Public License along with this program; + * if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +package org.rhq.core.clientapi.agent.bundle; + +import java.io.Serializable; + +import org.rhq.core.util.exception.ThrowableUtil; + +/** + * @author John Mazzitelli + */ +public class BundleScheduleResponse implements Serializable { + private static final long serialVersionUID = 1L; + + private String errorMessage; + + public BundleScheduleResponse() { + } + + public boolean isSuccess() { + return this.errorMessage == null; + } + + public String getErrorMessage() { + return this.errorMessage; + } + + public void setErrorMessage(String errorMessage) { + this.errorMessage = errorMessage; + } + + public void setErrorMessage(Throwable t) { + this.errorMessage = ThrowableUtil.getAllMessages(t); + } + + @Override + public String toString() { + StringBuilder str = new StringBuilder(this.getClass().getSimpleName()); + if (getErrorMessage() != null) { + str.append(" error=[").append(getErrorMessage()).append("];"); + } + str.append(" success=[").append(isSuccess()).append("]"); + return str.toString(); + } +} diff --git a/modules/core/client-api/src/main/java/org/rhq/core/clientapi/agent/bundle/BundleUpdateRequest.java b/modules/core/client-api/src/main/java/org/rhq/core/clientapi/agent/bundle/BundleUpdateRequest.java deleted file mode 100644 index ba0f7b1..0000000 --- a/modules/core/client-api/src/main/java/org/rhq/core/clientapi/agent/bundle/BundleUpdateRequest.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * RHQ Management Platform - * Copyright (C) 2005-2008 Red Hat, Inc. - * All rights reserved. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, as - * published by the Free Software Foundation, and/or the GNU Lesser - * General Public License, version 2.1, also as published by the Free - * Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License and the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU General Public License - * and the GNU Lesser General Public License along with this program; - * if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -package org.rhq.core.clientapi.agent.bundle; - -/** - * @author John Mazzitelli - */ -public class BundleUpdateRequest { - -} diff --git a/modules/core/client-api/src/main/java/org/rhq/core/clientapi/agent/bundle/BundleUpdateResponse.java b/modules/core/client-api/src/main/java/org/rhq/core/clientapi/agent/bundle/BundleUpdateResponse.java deleted file mode 100644 index 9482fb5..0000000 --- a/modules/core/client-api/src/main/java/org/rhq/core/clientapi/agent/bundle/BundleUpdateResponse.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * RHQ Management Platform - * Copyright (C) 2005-2008 Red Hat, Inc. - * All rights reserved. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, as - * published by the Free Software Foundation, and/or the GNU Lesser - * General Public License, version 2.1, also as published by the Free - * Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License and the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU General Public License - * and the GNU Lesser General Public License along with this program; - * if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -package org.rhq.core.clientapi.agent.bundle; - -/** - * @author John Mazzitelli - */ -public class BundleUpdateResponse { - -} diff --git a/modules/core/client-api/src/main/java/org/rhq/core/clientapi/server/bundle/BundleServerService.java b/modules/core/client-api/src/main/java/org/rhq/core/clientapi/server/bundle/BundleServerService.java index 2d71236..eb09a4e 100644 --- a/modules/core/client-api/src/main/java/org/rhq/core/clientapi/server/bundle/BundleServerService.java +++ b/modules/core/client-api/src/main/java/org/rhq/core/clientapi/server/bundle/BundleServerService.java @@ -22,7 +22,10 @@ */ package org.rhq.core.clientapi.server.bundle;
+import java.util.List; + import org.rhq.core.communications.command.annotation.Asynchronous; +import org.rhq.core.domain.bundle.BundleFile;
/** * Interface for agents to use when needing to inform the server about bundle tasks. Implementations of this interface, once registered with the @@ -33,5 +36,7 @@ import org.rhq.core.communications.command.annotation.Asynchronous; public interface BundleServerService {
@Asynchronous(guaranteedDelivery = true) - void updateComplete(BundleUpdateComplete buc); + void updateStatus(BundleStatusUpdate update); + + List<BundleFile> getAllBundleFiles(int bundleVersionId); } \ No newline at end of file diff --git a/modules/core/client-api/src/main/java/org/rhq/core/clientapi/server/bundle/BundleStatusUpdate.java b/modules/core/client-api/src/main/java/org/rhq/core/clientapi/server/bundle/BundleStatusUpdate.java new file mode 100644 index 0000000..99bdda8 --- /dev/null +++ b/modules/core/client-api/src/main/java/org/rhq/core/clientapi/server/bundle/BundleStatusUpdate.java @@ -0,0 +1,33 @@ +/* + * RHQ Management Platform + * Copyright (C) 2005-2008 Red Hat, Inc. + * All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License, version 2, as + * published by the Free Software Foundation, and/or the GNU Lesser + * General Public License, version 2.1, also as published by the Free + * Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License and the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License + * and the GNU Lesser General Public License along with this program; + * if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.rhq.core.clientapi.server.bundle; + +/** + * Object that informs the server that a bundle deployment has a new status. + * This will be the way the bundle deployment process is tracked. + * + * @author John Mazzitelli + */ +public class BundleStatusUpdate { + +} diff --git a/modules/core/client-api/src/main/java/org/rhq/core/clientapi/server/bundle/BundleUpdateComplete.java b/modules/core/client-api/src/main/java/org/rhq/core/clientapi/server/bundle/BundleUpdateComplete.java deleted file mode 100644 index 0314857..0000000 --- a/modules/core/client-api/src/main/java/org/rhq/core/clientapi/server/bundle/BundleUpdateComplete.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * RHQ Management Platform - * Copyright (C) 2005-2008 Red Hat, Inc. - * All rights reserved. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, as - * published by the Free Software Foundation, and/or the GNU Lesser - * General Public License, version 2.1, also as published by the Free - * Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License and the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU General Public License - * and the GNU Lesser General Public License along with this program; - * if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.rhq.core.clientapi.server.bundle; - -/** - * - * @author John Mazzitelli - */ -public class BundleUpdateComplete { - -} diff --git a/modules/core/plugin-api/src/main/java/org/rhq/core/pluginapi/bundle/BundleDeployRequest.java b/modules/core/plugin-api/src/main/java/org/rhq/core/pluginapi/bundle/BundleDeployRequest.java new file mode 100644 index 0000000..40e663b --- /dev/null +++ b/modules/core/plugin-api/src/main/java/org/rhq/core/pluginapi/bundle/BundleDeployRequest.java @@ -0,0 +1,54 @@ +/* + * RHQ Management Platform + * Copyright (C) 2005-2009 Red Hat, Inc. + * All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +package org.rhq.core.pluginapi.bundle; + +import java.io.Serializable; + +import org.rhq.core.domain.bundle.BundleDeployDefinition; +import org.rhq.core.pc.bundle.BundleManager; + +/** + * A request to deploy a bundle. + * + * @author John Mazzitelli + */ +public class BundleDeployRequest implements Serializable { + private static final long serialVersionUID = 1L; + + private BundleDeployDefinition bundleDeployDefinition; + private BundleManager bundleManager; + + public BundleDeployDefinition getBundleDeployDefinition() { + return bundleDeployDefinition; + } + + public void setBundleDeployDefinition(BundleDeployDefinition bundleDeployDefinition) { + this.bundleDeployDefinition = bundleDeployDefinition; + } + + public BundleManager getBundleManager() { + return bundleManager; + } + + public void setBundleManager(BundleManager bundleManager) { + this.bundleManager = bundleManager; + } + +} diff --git a/modules/core/plugin-api/src/main/java/org/rhq/core/pluginapi/bundle/BundleDeployResult.java b/modules/core/plugin-api/src/main/java/org/rhq/core/pluginapi/bundle/BundleDeployResult.java new file mode 100644 index 0000000..b2b3628 --- /dev/null +++ b/modules/core/plugin-api/src/main/java/org/rhq/core/pluginapi/bundle/BundleDeployResult.java @@ -0,0 +1,64 @@ +/* + * RHQ Management Platform + * Copyright (C) 2005-2010 Red Hat, Inc. + * All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License, version 2, as + * published by the Free Software Foundation, and/or the GNU Lesser + * General Public License, version 2.1, also as published by the Free + * Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License and the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License + * and the GNU Lesser General Public License along with this program; + * if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.rhq.core.pluginapi.bundle; + +import java.io.Serializable; + +import org.rhq.core.util.exception.ThrowableUtil; + +/** + * The results after an attempt to deploy a bundle has been completed. + * @author John Mazzitelli + */ +public class BundleDeployResult implements Serializable { + private static final long serialVersionUID = 1L; + + private String errorMessage; + + public boolean isSuccess() { + return this.errorMessage == null; + } + + public String getErrorMessage() { + return this.errorMessage; + } + + public void setErrorMessage(String errorMessage) { + this.errorMessage = errorMessage; + } + + public void setErrorMessage(Throwable t) { + this.errorMessage = ThrowableUtil.getAllMessages(t); + } + + @Override + public String toString() { + StringBuilder str = new StringBuilder(this.getClass().getSimpleName()); + if (getErrorMessage() != null) { + str.append(" error=[").append(getErrorMessage()).append("];"); + } + str.append(" success=[").append(isSuccess()).append("]"); + return str.toString(); + } + +} diff --git a/modules/core/plugin-api/src/main/java/org/rhq/core/pluginapi/bundle/BundleFacet.java b/modules/core/plugin-api/src/main/java/org/rhq/core/pluginapi/bundle/BundleFacet.java index cb5ea35..2b76c0c 100644 --- a/modules/core/plugin-api/src/main/java/org/rhq/core/pluginapi/bundle/BundleFacet.java +++ b/modules/core/plugin-api/src/main/java/org/rhq/core/pluginapi/bundle/BundleFacet.java @@ -28,4 +28,5 @@ package org.rhq.core.pluginapi.bundle; * @author John Mazzitelli */ public interface BundleFacet { + BundleDeployResult deployBundle(BundleDeployRequest request); } diff --git a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/ServerServices.java b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/ServerServices.java index e109755..33951b6 100644 --- a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/ServerServices.java +++ b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/ServerServices.java @@ -1,35 +1,36 @@ - /* - * RHQ Management Platform - * Copyright (C) 2005-2008 Red Hat, Inc. - * All rights reserved. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, as - * published by the Free Software Foundation, and/or the GNU Lesser - * General Public License, version 2.1, also as published by the Free - * Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License and the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU General Public License - * and the GNU Lesser General Public License along with this program; - * if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ +/* + * RHQ Management Platform + * Copyright (C) 2005-2008 Red Hat, Inc. + * All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License, version 2, as + * published by the Free Software Foundation, and/or the GNU Lesser + * General Public License, version 2.1, also as published by the Free + * Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License and the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License + * and the GNU Lesser General Public License along with this program; + * if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ package org.rhq.core.pc;
+import org.rhq.core.clientapi.server.bundle.BundleServerService; import org.rhq.core.clientapi.server.configuration.ConfigurationServerService; import org.rhq.core.clientapi.server.content.ContentServerService; import org.rhq.core.clientapi.server.core.CoreServerService; import org.rhq.core.clientapi.server.discovery.DiscoveryServerService; +import org.rhq.core.clientapi.server.event.EventServerService; import org.rhq.core.clientapi.server.inventory.ResourceFactoryServerService; import org.rhq.core.clientapi.server.measurement.MeasurementServerService; import org.rhq.core.clientapi.server.operation.OperationServerService; -import org.rhq.core.clientapi.server.event.EventServerService;
/** * Provides access to remote pojo's representing the JON Server's client interfaces. These server service interfaces are @@ -49,6 +50,7 @@ public class ServerServices { private ResourceFactoryServerService resourceFactoryServerService; private ContentServerService contentServerService; private EventServerService eventServerService; + private BundleServerService bundleServerService;
public CoreServerService getCoreServerService() { return coreServerService; @@ -113,4 +115,13 @@ public class ServerServices { public void setEventServerService(EventServerService eventServerService) { this.eventServerService = eventServerService; } + + public BundleServerService getBundleServerService() { + return bundleServerService; + } + + public void setBundleServerService(BundleServerService bundleServerService) { + this.bundleServerService = bundleServerService; + } + } \ No newline at end of file diff --git a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/bundle/BundleManager.java b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/bundle/BundleManager.java index ff92d8c..4ab1c03 100644 --- a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/bundle/BundleManager.java +++ b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/bundle/BundleManager.java @@ -22,15 +22,32 @@ */ package org.rhq.core.pc.bundle;
+import java.util.List; +import java.util.Set; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + import org.rhq.core.clientapi.agent.PluginContainerException; import org.rhq.core.clientapi.agent.bundle.BundleAgentService; -import org.rhq.core.clientapi.agent.bundle.BundleUpdateRequest; -import org.rhq.core.clientapi.agent.bundle.BundleUpdateResponse; +import org.rhq.core.clientapi.agent.bundle.BundleScheduleRequest; +import org.rhq.core.clientapi.agent.bundle.BundleScheduleResponse; +import org.rhq.core.clientapi.server.bundle.BundleServerService; +import org.rhq.core.domain.bundle.BundleDeployDefinition; +import org.rhq.core.domain.bundle.BundleFile; +import org.rhq.core.domain.bundle.BundleType; +import org.rhq.core.domain.bundle.BundleVersion; +import org.rhq.core.domain.resource.Resource; +import org.rhq.core.domain.resource.ResourceType; import org.rhq.core.pc.ContainerService; +import org.rhq.core.pc.PluginContainer; import org.rhq.core.pc.PluginContainerConfiguration; import org.rhq.core.pc.agent.AgentService; +import org.rhq.core.pc.inventory.InventoryManager; import org.rhq.core.pc.util.ComponentUtil; import org.rhq.core.pc.util.FacetLockType; +import org.rhq.core.pluginapi.bundle.BundleDeployRequest; +import org.rhq.core.pluginapi.bundle.BundleDeployResult; import org.rhq.core.pluginapi.bundle.BundleFacet;
/** @@ -41,12 +58,16 @@ import org.rhq.core.pluginapi.bundle.BundleFacet; * @author John Mazzitelli */ public class BundleManager extends AgentService implements BundleAgentService, ContainerService { + private final Log log = LogFactory.getLog(BundleManager.class); + + private PluginContainerConfiguration configuration;
public BundleManager() { super(BundleAgentService.class); }
public void setConfiguration(PluginContainerConfiguration configuration) { + this.configuration = configuration; }
public void initialize() { @@ -55,9 +76,66 @@ public class BundleManager extends AgentService implements BundleAgentService, C public void shutdown() { }
- public BundleUpdateResponse update(BundleUpdateRequest request) { - // TODO Auto-generated method stub - return null; + public BundleScheduleResponse schedule(BundleScheduleRequest request) { + BundleScheduleResponse response = new BundleScheduleResponse(); + + try { + BundleDeployDefinition bundleDef = request.getBundleDeployDefinition(); + + // find the resource that will handle the bundle processing + InventoryManager im = PluginContainer.getInstance().getInventoryManager(); + BundleType bundleType = bundleDef.getBundleVersion().getBundle().getBundleType(); + ResourceType resourceType = bundleType.getResourceType(); + Set<Resource> resources = im.getResourcesWithType(resourceType); + if (resources.isEmpty()) { + throw new Exception("No bundle plugin supports bundle type [" + bundleType + "]"); + } + int bundleHandlerResourceId = resources.iterator().next().getId(); + + // get the bundle facet object that will process the bundle + int facetMethodTimeout = 4 * 60 * 60 * 1000; // 4 hours is given to the bundle plugin to do its thing + BundleFacet bundlePluginComponent = getBundleFacet(bundleHandlerResourceId, facetMethodTimeout); + + // deploy the bundle utilizing the bundle facet object + BundleDeployRequest deployRequest = new BundleDeployRequest(); + deployRequest.setBundleManager(this); + deployRequest.setBundleDeployDefinition(request.getBundleDeployDefinition()); + BundleDeployResult result = bundlePluginComponent.deployBundle(deployRequest); + if (!result.isSuccess()) { + response.setErrorMessage(result.getErrorMessage()); + } + } catch (Throwable t) { + log.error("Failed to schedule bundle request: " + request, t); + response.setErrorMessage(t); + } + + return response; + } + + /** + * This is used by bundle plugins - bundle plugins call back into this manager to obtain the + * bundle files that belong to a given bundle version. + * + * @param bundleVersion + * @return the bundle files that are associated with the given bundle + * @throws Exception + */ + public List<BundleFile> getAllBundleFiles(BundleVersion bundleVersion) throws Exception { + List<BundleFile> bundleFiles = getBundleServerService().getAllBundleFiles(bundleVersion.getId()); + return bundleFiles; + } + + /** + * If this manager can talk to a server-side {@link BundleServerService}, a proxy to that service is returned. + * + * @return the server-side proxy; <code>null</code> if this manager doesn't have a server to talk to + */ + private BundleServerService getBundleServerService() { + if (configuration.getServerServices() != null) { + return configuration.getServerServices().getBundleServerService(); + } + + throw new IllegalStateException("There is no bundle server service available to obtain bundle files"); }
/** @@ -66,13 +144,14 @@ public class BundleManager extends AgentService implements BundleAgentService, C * The resource must be in the STARTED (i.e. connected) state. * * @param resourceId identifies the resource that is to perform the bundle activities + * @param timeout if any facet method invocation thread has not completed after this many milliseconds, interrupt + * it; value must be positive * * @return the resource's bundle facet interface * * @throws PluginContainerException on error */ - protected BundleFacet getBundleFacet(int resourceId, long facetMethodTimeout) throws PluginContainerException { - return ComponentUtil.getComponent(resourceId, BundleFacet.class, FacetLockType.READ, facetMethodTimeout, false, - true); + private BundleFacet getBundleFacet(int resourceId, long timeout) throws PluginContainerException { + return ComponentUtil.getComponent(resourceId, BundleFacet.class, FacetLockType.READ, timeout, false, true); } } diff --git a/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentMain.java b/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentMain.java index 94513d0..19624fa 100644 --- a/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentMain.java +++ b/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentMain.java @@ -68,6 +68,7 @@ import org.jboss.remoting.security.SSLSocketBuilder; import org.jboss.remoting.transport.http.ssl.HTTPSClientInvoker; import org.jboss.util.StringPropertyReplacer;
+import org.rhq.core.clientapi.server.bundle.BundleServerService; import org.rhq.core.clientapi.server.configuration.ConfigurationServerService; import org.rhq.core.clientapi.server.content.ContentServerService; import org.rhq.core.clientapi.server.core.AgentNotSupportedException; @@ -1648,6 +1649,7 @@ public class AgentMain { .getRemotePojo(ResourceFactoryServerService.class); ContentServerService contentServerService = factory.getRemotePojo(ContentServerService.class); EventServerService eventServerService = factory.getRemotePojo(EventServerService.class); + BundleServerService bundleServerService = factory.getRemotePojo(BundleServerService.class);
ServerServices serverServices = new ServerServices(); serverServices.setCoreServerService(coreServerService); @@ -1658,6 +1660,7 @@ public class AgentMain { serverServices.setResourceFactoryServerService(resourceFactoryServerSerfice); serverServices.setContentServerService(contentServerService); serverServices.setEventServerService(eventServerService); + serverServices.setBundleServerService(bundleServerService);
pc_config.setServerServices(serverServices); } catch (Exception e) { diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/bundle/BundleServerServiceImpl.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/bundle/BundleServerServiceImpl.java index a676704..fa84821 100644 --- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/bundle/BundleServerServiceImpl.java +++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/bundle/BundleServerServiceImpl.java @@ -18,11 +18,14 @@ */ package org.rhq.enterprise.server.bundle;
+import java.util.List; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory;
import org.rhq.core.clientapi.server.bundle.BundleServerService; -import org.rhq.core.clientapi.server.bundle.BundleUpdateComplete; +import org.rhq.core.clientapi.server.bundle.BundleStatusUpdate; +import org.rhq.core.domain.bundle.BundleFile;
/** * Server-side implementation of the <code>BundleServerService</code>. This implmentation simply forwards @@ -33,7 +36,11 @@ import org.rhq.core.clientapi.server.bundle.BundleUpdateComplete; public class BundleServerServiceImpl implements BundleServerService { private final Log log = LogFactory.getLog(this.getClass());
- public void updateComplete(BundleUpdateComplete buc) { + public void updateStatus(BundleStatusUpdate update) { // TODO Auto-generated method stub } + + public List<BundleFile> getAllBundleFiles(int bundleVersionId) { + return null; + } } \ No newline at end of file diff --git a/modules/plugins/filetemplate-bundle/src/main/java/org/rhq/plugins/filetemplate/FileTemplateBundlePluginServerComponent.java b/modules/plugins/filetemplate-bundle/src/main/java/org/rhq/plugins/filetemplate/FileTemplateBundlePluginServerComponent.java index 08eb7b4..a7100ec 100644 --- a/modules/plugins/filetemplate-bundle/src/main/java/org/rhq/plugins/filetemplate/FileTemplateBundlePluginServerComponent.java +++ b/modules/plugins/filetemplate-bundle/src/main/java/org/rhq/plugins/filetemplate/FileTemplateBundlePluginServerComponent.java @@ -22,6 +22,8 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory;
import org.rhq.core.domain.measurement.AvailabilityType; +import org.rhq.core.pluginapi.bundle.BundleDeployRequest; +import org.rhq.core.pluginapi.bundle.BundleDeployResult; import org.rhq.core.pluginapi.bundle.BundleFacet; import org.rhq.core.pluginapi.inventory.ResourceComponent; import org.rhq.core.pluginapi.inventory.ResourceContext; @@ -46,4 +48,11 @@ public class FileTemplateBundlePluginServerComponent implements ResourceComponen public AvailabilityType getAvailability() { return AvailabilityType.UP; } + + @Override + public BundleDeployResult deployBundle(BundleDeployRequest request) { + // TODO + BundleDeployResult result = new BundleDeployResult(); + return result; + } }
rhq-commits@lists.fedorahosted.org