From 7b64f309042093a27edff834ac1b62afc8610d9c Mon Sep 17 00:00:00 2001 From: oldpatricka Date: Thu, 2 Dec 2010 15:49:04 -0800 Subject: [PATCH] Refactor CustomizationNeed to FileCopyNeed. This way it can also be used for files that need to be copied to the VMM node at Propagate time (credentials). This also means that files that are contexed in are copied at propagation time, rather than start time, as in the past. --- .../lib/workspace_service_derby_schema.sql | 11 ++- .../creation/defaults/DefaultCreation.java | 8 +- .../persistence/PersistenceAdapter.java | 6 +- .../PersistenceAdapterConstants.java | 26 +++--- .../persistence/PersistenceAdapterImpl.java | 22 ++--- .../impls/VirtualMachinePersistenceUtil.java | 16 ++-- .../workspace/service/InstanceResource.java | 4 +- .../service/binding/BindCustomizations.java | 4 +- .../service/binding/BindingAdapter.java | 4 +- .../defaults/DefaultBindCredential.java | 18 +++- .../defaults/DefaultBindCustomizations.java | 12 +-- .../defaults/DefaultBindingAdapter.java | 7 +- ...stomizationNeed.java => FileCopyNeed.java} | 82 +++++++++-------- .../service/binding/vm/VirtualMachine.java | 42 ++++----- .../service/impls/InstanceResourceImpl.java | 6 +- .../src/org/globus/workspace/xen/XenUtil.java | 90 +++---------------- .../globus/workspace/xen/xenlocal/Start.java | 8 +- .../workspace/xen/xenssh/Propagate.java | 60 ++++++++----- .../globus/workspace/xen/xenssh/Start.java | 38 +------- .../lib/workspace_service_derby_schema.sql | 6 +- 20 files changed, 203 insertions(+), 267 deletions(-) rename service/service/java/source/src/org/globus/workspace/service/binding/vm/{CustomizationNeed.java => FileCopyNeed.java} (56%) diff --git a/service/service/java/source/share/lib/workspace_service_derby_schema.sql b/service/service/java/source/share/lib/workspace_service_derby_schema.sql index b5dc6104..bd8de6a1 100644 --- a/service/service/java/source/share/lib/workspace_service_derby_schema.sql +++ b/service/service/java/source/share/lib/workspace_service_derby_schema.sql @@ -118,14 +118,14 @@ PRIMARY KEY(association,ipaddress) ); -- --- Persistence for file customization tasks +-- Persistence for file copy tasks -CREATE TABLE vm_customization +CREATE TABLE file_copy ( vmid INT NOT NULL, -sourcepath VARCHAR(32) NOT NULL, -destpath VARCHAR(512) NOT NULL, -sent SMALLINT NOT NULL +sourcepath VARCHAR(36) NOT NULL, +destpath VARCHAR(512), +on_image SMALLINT NOT NULL ); -- @@ -158,7 +158,6 @@ CREATE TABLE default_scheduler_done_ensemb coschedid CHAR(36) NOT NULL ); - -- using REAL for memory attributs to allow -- real division operations in ORDER BY statements diff --git a/service/service/java/source/src/org/globus/workspace/creation/defaults/DefaultCreation.java b/service/service/java/source/src/org/globus/workspace/creation/defaults/DefaultCreation.java index e0308e42..95832261 100644 --- a/service/service/java/source/src/org/globus/workspace/creation/defaults/DefaultCreation.java +++ b/service/service/java/source/src/org/globus/workspace/creation/defaults/DefaultCreation.java @@ -44,7 +44,7 @@ import org.globus.workspace.service.binding.GlobalPolicies; import org.globus.workspace.service.binding.vm.VirtualMachine; import org.globus.workspace.service.binding.vm.VirtualMachineDeployment; -import org.globus.workspace.service.binding.vm.CustomizationNeed; +import org.globus.workspace.service.binding.vm.FileCopyNeed; import org.nimbustools.api._repr._CreateResult; import org.nimbustools.api._repr._Advertised; @@ -891,10 +891,10 @@ protected VM createOne(int idx, try { final String newContent = addIPs(context.getBootstrapText(), vm); - final CustomizationNeed need = - this.binding.newCustomizationNeed( + final FileCopyNeed need = + this.binding.newFileCopyNeed( newContent, context.getBootstrapPath()); - resource.newCustomizationNeed(need); + resource.newFileCopyNeed(need); } catch (Exception e) { logger.error(e.getMessage()); } diff --git a/service/service/java/source/src/org/globus/workspace/persistence/PersistenceAdapter.java b/service/service/java/source/src/org/globus/workspace/persistence/PersistenceAdapter.java index 317f1ff0..a50f39fe 100644 --- a/service/service/java/source/src/org/globus/workspace/persistence/PersistenceAdapter.java +++ b/service/service/java/source/src/org/globus/workspace/persistence/PersistenceAdapter.java @@ -25,7 +25,7 @@ import org.globus.workspace.service.CoschedResource; import org.globus.workspace.service.GroupResource; import org.globus.workspace.service.InstanceResource; -import org.globus.workspace.service.binding.vm.CustomizationNeed; +import org.globus.workspace.service.binding.vm.FileCopyNeed; import org.nimbustools.api.services.rm.DoesNotExistException; /** @@ -62,7 +62,7 @@ public void setRootUnpropTarget(int id, String path) throws WorkspaceDatabaseException; - public void setCustomizeTaskSent(int id, CustomizationNeed need) + public void setFileCopyOnImage(int id, FileCopyNeed need) throws WorkspaceDatabaseException; @@ -172,7 +172,7 @@ public boolean removeResourcepoolEntry(String hostname) throws WorkspaceDatabaseException; - public void addCustomizationNeed(int id, CustomizationNeed need) + public void addCustomizationNeed(int id, FileCopyNeed need) throws WorkspaceDatabaseException; diff --git a/service/service/java/source/src/org/globus/workspace/persistence/PersistenceAdapterConstants.java b/service/service/java/source/src/org/globus/workspace/persistence/PersistenceAdapterConstants.java index bc4c87eb..7b6ec58d 100644 --- a/service/service/java/source/src/org/globus/workspace/persistence/PersistenceAdapterConstants.java +++ b/service/service/java/source/src/org/globus/workspace/persistence/PersistenceAdapterConstants.java @@ -58,8 +58,8 @@ public interface PersistenceAdapterConstants { "UPDATE vm_partitions SET alternate_unprop=? " + "WHERE vmid=? AND rootdisk=1"; - public static final String SQL_SET_VM_CUSTOMIZATION_SENT = - "UPDATE vm_customization SET sent=? " + + public static final String SQL_SET_FILE_COPY_ON_IMAGE = + "UPDATE file_copy SET on_image=? " + "WHERE vmid=? AND sourcepath=? AND destpath=?"; public static final String SQL_SET_STARTTIME = @@ -83,8 +83,8 @@ public interface PersistenceAdapterConstants { public static final String SQL_DELETE_VM_DEPLOYMENT = "DELETE from vm_deployment WHERE vmid=?"; - public static final String SQL_DELETE_VM_CUSTOMIZATION = - "DELETE from vm_customization WHERE vmid=?"; + public static final String SQL_DELETE_FILE_COPY = + "DELETE from file_copy WHERE vmid=?"; public static final String SQL_INSERT_RESOURCE = "INSERT INTO resources VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; @@ -101,8 +101,8 @@ public interface PersistenceAdapterConstants { public static final String SQL_INSERT_VM_DEPLOYMENT = "INSERT INTO vm_deployment VALUES(?,?,?,?,?,?)"; - public static final String SQL_INSERT_VM_CUSTOMIZATION = - "INSERT INTO vm_customization VALUES(?,?,?,?)"; + public static final String SQL_INSERT_FILE_COPY = + "INSERT INTO file_copy VALUES(?,?,?,?)"; public static final String SQL_LOAD_RESOURCE = "SELECT name, state, target_state, term_time, ops_enabled, " + @@ -133,9 +133,9 @@ public interface PersistenceAdapterConstants { "ind_physmem, ind_physcpu " + "FROM vm_deployment WHERE vmid=?"; - public static final String SQL_LOAD_VM_CUSTOMIZATION = - "SELECT sourcepath, destpath, sent " + - "FROM vm_customization WHERE vmid=?"; + public static final String SQL_LOAD_FILE_COPY = + "SELECT sourcepath, destpath, on_image " + + "FROM file_copy WHERE vmid=?"; public static final String SQL_UPDATE_ASSOCIATION_ENTRY = "UPDATE association_entries SET used=? " + @@ -203,7 +203,7 @@ public interface PersistenceAdapterConstants { SQL_SET_HOSTNAME, SQL_SET_ROOT_UNPROP_TARGET, SQL_UNSET_ROOT_UNPROP_TARGET, - SQL_SET_VM_CUSTOMIZATION_SENT, + SQL_SET_FILE_COPY_ON_IMAGE, SQL_SET_STARTTIME, SQL_SET_TERMTIME, SQL_DELETE_RESOURCE, @@ -211,19 +211,19 @@ public interface PersistenceAdapterConstants { SQL_DELETE_VM, SQL_DELETE_VM_PARTITIONS, SQL_DELETE_VM_DEPLOYMENT, - SQL_DELETE_VM_CUSTOMIZATION, + SQL_DELETE_FILE_COPY, SQL_INSERT_RESOURCE, SQL_INSERT_VM, SQL_INSERT_VM_PARTITION, SQL_INSERT_VM_DEPLOYMENT, - SQL_INSERT_VM_CUSTOMIZATION, + SQL_INSERT_FILE_COPY, SQL_LOAD_RESOURCE, SQL_LOAD_RESOURCE_NAME, SQL_LOAD_GROUP_RESOURCE, SQL_LOAD_VM, SQL_LOAD_VM_PARTITIONS, SQL_LOAD_VM_DEPLOYMENT, - SQL_LOAD_VM_CUSTOMIZATION, + SQL_LOAD_FILE_COPY, SQL_UPDATE_ASSOCIATION_ENTRY, SQL_DELETE_ALL_ASSOCIATIONS, SQL_DELETE_ALL_ASSOCIATION_ENTRIES, diff --git a/service/service/java/source/src/org/globus/workspace/persistence/PersistenceAdapterImpl.java b/service/service/java/source/src/org/globus/workspace/persistence/PersistenceAdapterImpl.java index 632852f5..616dc5ed 100644 --- a/service/service/java/source/src/org/globus/workspace/persistence/PersistenceAdapterImpl.java +++ b/service/service/java/source/src/org/globus/workspace/persistence/PersistenceAdapterImpl.java @@ -41,7 +41,7 @@ import org.globus.workspace.service.CoschedResource; import org.globus.workspace.service.GroupResource; import org.globus.workspace.service.InstanceResource; -import org.globus.workspace.service.binding.vm.CustomizationNeed; +import org.globus.workspace.service.binding.vm.FileCopyNeed; import org.globus.workspace.service.binding.vm.VirtualMachine; import org.globus.workspace.service.binding.vm.VirtualMachinePartition; import org.nimbustools.api.services.rm.DoesNotExistException; @@ -489,11 +489,11 @@ public void setRootUnpropTarget(int id, String path) } } - public void addCustomizationNeed(int id, CustomizationNeed need) + public void addCustomizationNeed(int id, FileCopyNeed need) throws WorkspaceDatabaseException { if (this.dbTrace) { - logger.trace("addCustomizationNeed(): " + Lager.id(id)); + logger.trace("addFileCopyNeed(): " + Lager.id(id)); } if (need == null) { @@ -504,12 +504,12 @@ public void addCustomizationNeed(int id, CustomizationNeed need) PreparedStatement pstmt = null; try { c = getConnection(); - pstmt = c.prepareStatement(SQL_INSERT_VM_CUSTOMIZATION); + pstmt = c.prepareStatement(SQL_INSERT_FILE_COPY); pstmt.setInt(1, id); pstmt.setString(2, need.sourcePath); pstmt.setString(3, need.destPath); - if (need.isSent()) { + if (need.onImage()) { pstmt.setInt(4, 1); } else { pstmt.setInt(4, 0); @@ -538,20 +538,20 @@ public void addCustomizationNeed(int id, CustomizationNeed need) } } - public void setCustomizeTaskSent(int id, CustomizationNeed need) + public void setFileCopyOnImage(int id, FileCopyNeed need) throws WorkspaceDatabaseException { if (this.dbTrace) { - logger.trace("setCustomizeTaskSent(): " + Lager.id(id) + - ", sent = " + need.isSent()); + logger.trace("setFileCopyOnImage(): " + Lager.id(id) + + ", on image = " + need.onImage()); } Connection c = null; PreparedStatement pstmt = null; try { c = getConnection(); - pstmt = c.prepareStatement(SQL_SET_VM_CUSTOMIZATION_SENT); - if (need.isSent()) { + pstmt = c.prepareStatement(SQL_SET_FILE_COPY_ON_IMAGE); + if (need.onImage()) { pstmt.setInt(1, 1); } else { pstmt.setInt(1, 0); @@ -1430,7 +1430,7 @@ public void load(int id, InstanceResource resource) } } else { do { - vm.addCustomizationNeed( + vm.addFileCopyNeed( VirtualMachinePersistenceUtil.getNeed(rs)); } while (rs.next()); } diff --git a/service/service/java/source/src/org/globus/workspace/persistence/impls/VirtualMachinePersistenceUtil.java b/service/service/java/source/src/org/globus/workspace/persistence/impls/VirtualMachinePersistenceUtil.java index 4469ee05..ce1f5d21 100644 --- a/service/service/java/source/src/org/globus/workspace/persistence/impls/VirtualMachinePersistenceUtil.java +++ b/service/service/java/source/src/org/globus/workspace/persistence/impls/VirtualMachinePersistenceUtil.java @@ -20,10 +20,10 @@ import org.globus.workspace.persistence.PersistenceAdapterConstants; import org.globus.workspace.persistence.WorkspaceDatabaseException; import org.globus.workspace.service.InstanceResource; +import org.globus.workspace.service.binding.vm.FileCopyNeed; import org.globus.workspace.service.binding.vm.VirtualMachine; import org.globus.workspace.service.binding.vm.VirtualMachineDeployment; import org.globus.workspace.service.binding.vm.VirtualMachinePartition; -import org.globus.workspace.service.binding.vm.CustomizationNeed; import org.nimbustools.api.services.rm.ManageException; import java.sql.Connection; @@ -192,15 +192,15 @@ public static PreparedStatement[] getInsertVM(InstanceResource resource, } } - final CustomizationNeed[] needs = vm.getCustomizationNeeds(); + final FileCopyNeed[] needs = vm.getFileCopyNeeds(); if (needs != null) { for (int i = 0; i < needs.length; i++) { final PreparedStatement custStmt = - c.prepareStatement(SQL_INSERT_VM_CUSTOMIZATION); + c.prepareStatement(SQL_INSERT_FILE_COPY); custStmt.setInt(1, id); custStmt.setString(2, needs[i].sourcePath); custStmt.setString(3, needs[i].destPath); - if (needs[i].isSent()) { + if (needs[i].onImage()) { custStmt.setInt(4, 1); } else { custStmt.setInt(4, 0); @@ -249,7 +249,7 @@ public static PreparedStatement[] getRemoveVM( deletes.add(pstmt3); final PreparedStatement pstmt4 = - c.prepareStatement(SQL_DELETE_VM_CUSTOMIZATION); + c.prepareStatement(SQL_DELETE_FILE_COPY); pstmt4.setInt(1, id); deletes.add(pstmt4); @@ -274,7 +274,7 @@ public static PreparedStatement[] getVMQuery(int id, Connection c) pstmt3.setInt(1, id); final PreparedStatement pstmt4 = - c.prepareStatement(SQL_LOAD_VM_CUSTOMIZATION); + c.prepareStatement(SQL_LOAD_FILE_COPY); pstmt4.setInt(1, id); final PreparedStatement[] selects = new PreparedStatement[4]; @@ -336,14 +336,14 @@ public static VirtualMachinePartition getPartition(ResultSet rs) return partition; } - public static CustomizationNeed getNeed(ResultSet rs) + public static FileCopyNeed getNeed(ResultSet rs) throws WorkspaceDatabaseException { try { final String src = rs.getString(1); final String dst = rs.getString(2); final boolean sent = rs.getBoolean(3); - return new CustomizationNeed(src, dst, sent); + return new FileCopyNeed(src, dst, sent); } catch (Exception e) { throw new WorkspaceDatabaseException(e.getMessage(), e); } diff --git a/service/service/java/source/src/org/globus/workspace/service/InstanceResource.java b/service/service/java/source/src/org/globus/workspace/service/InstanceResource.java index faa0b3ea..c2d6842f 100644 --- a/service/service/java/source/src/org/globus/workspace/service/InstanceResource.java +++ b/service/service/java/source/src/org/globus/workspace/service/InstanceResource.java @@ -17,8 +17,8 @@ package org.globus.workspace.service; import org.globus.workspace.LockAcquisitionFailure; +import org.globus.workspace.service.binding.vm.FileCopyNeed; import org.globus.workspace.service.binding.vm.VirtualMachine; -import org.globus.workspace.service.binding.vm.CustomizationNeed; import org.nimbustools.api.services.rm.OperationDisabledException; import org.nimbustools.api.services.rm.DoesNotExistException; import org.nimbustools.api.services.rm.ManageException; @@ -161,7 +161,7 @@ public void reboot(ShutdownTasks tasks) public void newNetwork(String network); - public void newCustomizationNeed(CustomizationNeed need); + public void newFileCopyNeed(FileCopyNeed need); /** * Don't call unless you are managing the instance cache (or not using diff --git a/service/service/java/source/src/org/globus/workspace/service/binding/BindCustomizations.java b/service/service/java/source/src/org/globus/workspace/service/binding/BindCustomizations.java index f7b86947..32106092 100644 --- a/service/service/java/source/src/org/globus/workspace/service/binding/BindCustomizations.java +++ b/service/service/java/source/src/org/globus/workspace/service/binding/BindCustomizations.java @@ -17,7 +17,7 @@ package org.globus.workspace.service.binding; import org.globus.workspace.service.binding.vm.VirtualMachine; -import org.globus.workspace.service.binding.vm.CustomizationNeed; +import org.globus.workspace.service.binding.vm.FileCopyNeed; import org.globus.workspace.WorkspaceException; import org.nimbustools.api.repr.CustomizationRequest; import org.nimbustools.api.services.rm.CreationException; @@ -29,7 +29,7 @@ public void consume(VirtualMachine vm, CustomizationRequest[] reqs) throws CreationException, ResourceRequestDeniedException; - public CustomizationNeed newCustomizationNeedImpl(String srcContent, + public FileCopyNeed newFileCopyNeedImpl(String srcContent, String dstPath) throws WorkspaceException; } diff --git a/service/service/java/source/src/org/globus/workspace/service/binding/BindingAdapter.java b/service/service/java/source/src/org/globus/workspace/service/binding/BindingAdapter.java index 1e993d90..52bbb0dd 100644 --- a/service/service/java/source/src/org/globus/workspace/service/binding/BindingAdapter.java +++ b/service/service/java/source/src/org/globus/workspace/service/binding/BindingAdapter.java @@ -17,8 +17,8 @@ package org.globus.workspace.service.binding; import org.globus.workspace.WorkspaceException; +import org.globus.workspace.service.binding.vm.FileCopyNeed; import org.globus.workspace.service.binding.vm.VirtualMachine; -import org.globus.workspace.service.binding.vm.CustomizationNeed; import org.nimbustools.api.repr.CreateRequest; import org.nimbustools.api.services.rm.ResourceRequestDeniedException; import org.nimbustools.api.services.rm.CreationException; @@ -67,7 +67,7 @@ public void backOutAllocations(VirtualMachine vm) public void backOutAllocations(VirtualMachine[] vms) throws WorkspaceException; - public CustomizationNeed newCustomizationNeed(String srcContent, + public FileCopyNeed newFileCopyNeed(String srcContent, String dstPath) throws WorkspaceException; } diff --git a/service/service/java/source/src/org/globus/workspace/service/binding/defaults/DefaultBindCredential.java b/service/service/java/source/src/org/globus/workspace/service/binding/defaults/DefaultBindCredential.java index 22f82a0d..40f3e723 100644 --- a/service/service/java/source/src/org/globus/workspace/service/binding/defaults/DefaultBindCredential.java +++ b/service/service/java/source/src/org/globus/workspace/service/binding/defaults/DefaultBindCredential.java @@ -20,6 +20,7 @@ import org.apache.commons.logging.LogFactory; import org.globus.workspace.PathConfigs; import org.globus.workspace.service.binding.BindCredential; +import org.globus.workspace.service.binding.vm.FileCopyNeed; import org.globus.workspace.service.binding.vm.VirtualMachine; import org.nimbustools.api.services.rm.CreationException; import org.safehaus.uuid.UUIDGenerator; @@ -55,9 +56,11 @@ else if (credential == null) { final String localTempDirectory = this.paths.getLocalTempDirPath(); final String credentialName = this.uuidGen.generateRandomBasedUUID().toString(); + final String localPath = localTempDirectory + "/" + credentialName; + try { - FileOutputStream out = new FileOutputStream(localTempDirectory + File.pathSeparator + credentialName); + FileOutputStream out = new FileOutputStream(localPath); out.write(credential.getBytes()); out.flush(); out.close(); @@ -65,7 +68,18 @@ else if (credential == null) { throw new CreationException("Couldn't save credential to " + localTempDirectory + ". " + e.getMessage()); } - logger.info("Saved credential to " + credentialName); + + final FileCopyNeed need; + try { + // FileCopyNeed expects a file in nimbus's tmp, not a full path + need = new FileCopyNeed(credentialName); + vm.addFileCopyNeed(need); + } catch (Exception e) { + final String err = "problem setting up file copy for credential: " + + credentialName + " : " + e.getMessage(); + throw new CreationException(err); + } + vm.setCredentialName(credentialName); } } diff --git a/service/service/java/source/src/org/globus/workspace/service/binding/defaults/DefaultBindCustomizations.java b/service/service/java/source/src/org/globus/workspace/service/binding/defaults/DefaultBindCustomizations.java index 7f846e26..0a7b8693 100644 --- a/service/service/java/source/src/org/globus/workspace/service/binding/defaults/DefaultBindCustomizations.java +++ b/service/service/java/source/src/org/globus/workspace/service/binding/defaults/DefaultBindCustomizations.java @@ -18,13 +18,13 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.globus.workspace.service.binding.vm.FileCopyNeed; import org.nimbustools.api.repr.CustomizationRequest; import org.nimbustools.api.services.rm.CreationException; import org.nimbustools.api.services.rm.ResourceRequestDeniedException; import org.globus.workspace.PathConfigs; import org.globus.workspace.WorkspaceException; import org.globus.workspace.service.binding.BindCustomizations; -import org.globus.workspace.service.binding.vm.CustomizationNeed; import org.globus.workspace.service.binding.vm.VirtualMachine; import org.safehaus.uuid.UUIDGenerator; @@ -110,7 +110,7 @@ public void consume(VirtualMachine vm, } } - public CustomizationNeed newCustomizationNeedImpl(String srcContent, + public FileCopyNeed newFileCopyNeedImpl(String srcContent, String dstPath) throws WorkspaceException { @@ -185,12 +185,12 @@ protected void bindFileWrites(VirtualMachine vm, final String src = filewrites[i].getContent(); final String dstPath = filewrites[i].getPathOnVM(); - vm.addCustomizationNeed(this.newNeed(src, dstPath)); + vm.addFileCopyNeed(this.newNeed(src, dstPath)); } } - protected CustomizationNeed newNeed(String src, + protected FileCopyNeed newNeed(String src, String dstPath) throws Exception { // already checked, this is for object extenders @@ -217,9 +217,9 @@ protected CustomizationNeed newNeed(String src, final String srcPath = this.newSrcPath(); - final CustomizationNeed need; + final FileCopyNeed need; try { - need = new CustomizationNeed(srcPath, dstPath); + need = new FileCopyNeed(srcPath, dstPath); } catch (Exception e) { if (logger.isDebugEnabled()) { logger.error(e.getMessage(), e); diff --git a/service/service/java/source/src/org/globus/workspace/service/binding/defaults/DefaultBindingAdapter.java b/service/service/java/source/src/org/globus/workspace/service/binding/defaults/DefaultBindingAdapter.java index b49748ab..fc577cfe 100644 --- a/service/service/java/source/src/org/globus/workspace/service/binding/defaults/DefaultBindingAdapter.java +++ b/service/service/java/source/src/org/globus/workspace/service/binding/defaults/DefaultBindingAdapter.java @@ -18,8 +18,8 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.globus.workspace.PathConfigs; import org.globus.workspace.service.binding.*; +import org.globus.workspace.service.binding.vm.FileCopyNeed; import org.nimbustools.api.repr.CreateRequest; import org.nimbustools.api.repr.vm.ResourceAllocation; import org.nimbustools.api.services.rm.CreationException; @@ -36,7 +36,6 @@ import org.globus.workspace.service.binding.BindDisks; import org.globus.workspace.service.binding.BindVMM; import org.globus.workspace.service.binding.BindNetwork; -import org.globus.workspace.service.binding.vm.CustomizationNeed; import org.globus.workspace.service.binding.vm.VirtualMachine; import org.globus.workspace.service.binding.vm.VirtualMachineDeployment; @@ -214,12 +213,12 @@ public void backOutAllocations(VirtualMachine[] vms) // OTHER // ------------------------------------------------------------------------- - public CustomizationNeed newCustomizationNeed(String srcContent, + public FileCopyNeed newFileCopyNeed(String srcContent, String dstPath) throws WorkspaceException { return this.bindCustomizations - .newCustomizationNeedImpl(srcContent, dstPath); + .newFileCopyNeedImpl(srcContent, dstPath); } } diff --git a/service/service/java/source/src/org/globus/workspace/service/binding/vm/CustomizationNeed.java b/service/service/java/source/src/org/globus/workspace/service/binding/vm/FileCopyNeed.java similarity index 56% rename from service/service/java/source/src/org/globus/workspace/service/binding/vm/CustomizationNeed.java rename to service/service/java/source/src/org/globus/workspace/service/binding/vm/FileCopyNeed.java index d068078a..f7e95b58 100644 --- a/service/service/java/source/src/org/globus/workspace/service/binding/vm/CustomizationNeed.java +++ b/service/service/java/source/src/org/globus/workspace/service/binding/vm/FileCopyNeed.java @@ -21,7 +21,7 @@ * is 32 chars (UUID), destpath is is 512 chars and is the path ON the VM. * On the VMM, the file is also the UUID. */ -public class CustomizationNeed { +public class FileCopyNeed { public final static int srcMax = 36; public final static int dstMax = 512; @@ -33,16 +33,22 @@ public class CustomizationNeed { legalDestCharsString.toCharArray(); public final String sourcePath; + // A null destPath indicates that the file won't be copied to the VM public final String destPath; - boolean wasSent; + boolean onImage; - public CustomizationNeed(String src, String dst) + public FileCopyNeed(String src) + throws Exception { + this(src, null, false); + } + + public FileCopyNeed(String src, String dst) throws Exception { this(src, dst, false); } - public CustomizationNeed(String src, String dst, boolean sent) + public FileCopyNeed(String src, String dst, boolean onImage) throws Exception { if (src == null) { @@ -50,56 +56,56 @@ public CustomizationNeed(String src, String dst, boolean sent) } if (src.length() > srcMax) { throw new Exception( - "customization source path is too long: " + + "file copy source path is too long: " + src.length() + " > " + srcMax + ". Path: '" + src + "'"); } - if (dst == null) { - throw new IllegalArgumentException( - "destination path may not be null"); - } - if (dst.length() > dstMax) { - throw new Exception( - "customization destination path is too long: " + - dst.length() + " > " + dstMax + - ". Path: '" + dst + "'"); - } - // the mount tool would catch this too, but failfast - final char[] dstChars = dst.toCharArray(); - for (int i = 0; i < dstChars.length; i++) { - if (!legalChar(dstChars[i])) { + // If dst is null, file won't be copied onto the VM + if (dst != null) { + if (dst.length() > dstMax) { throw new Exception( - "customization destination path contains illegal " + - "character '" + dstChars[i] + "'. Path: '" + dst + "'"); + "file copy destination path is too long: " + + dst.length() + " > " + dstMax + + ". Path: '" + dst + "'"); } - } - if (dst.indexOf("../") >= 0) { - throw new Exception( - "customization destination path contains illegal " + - "path expansion, for example '../'. Path: '" + dst + "'"); + // the mount tool would catch this too, but failfast + final char[] dstChars = dst.toCharArray(); + for (int i = 0; i < dstChars.length; i++) { + if (!legalChar(dstChars[i])) { + throw new Exception( + "file copy destination path contains illegal " + + "character '" + dstChars[i] + "'. Path: '" + dst + "'"); + } + } + + if (dst.indexOf("../") >= 0) { + throw new Exception( + "file copy destination path contains illegal " + + "path expansion, for example '../'. Path: '" + dst + "'"); + } } this.sourcePath = src; this.destPath = dst; - this.wasSent = sent; + this.onImage = onImage; } // for clone only // 'fake' is just there to get around java limitation - private CustomizationNeed(String src, String dst, boolean sent, int fake) { + private FileCopyNeed(String src, String dst, boolean onImage, int fake) { this.sourcePath = src; this.destPath = dst; - this.wasSent = sent; + this.onImage = onImage; } - public synchronized boolean isSent() { - return this.wasSent; + public synchronized boolean onImage() { + return this.onImage; } - public synchronized void setSent(boolean sent) { - this.wasSent = sent; + public synchronized void setOnImage(boolean onImage) { + this.onImage = onImage; } private static boolean legalChar(char c) { @@ -111,28 +117,28 @@ private static boolean legalChar(char c) { return false; } - public static CustomizationNeed[] cloneArray(CustomizationNeed[] cur) + public static FileCopyNeed[] cloneArray(FileCopyNeed[] cur) throws Exception { if (cur == null) { return null; } - final CustomizationNeed[] newArr = new CustomizationNeed[cur.length]; + final FileCopyNeed[] newArr = new FileCopyNeed[cur.length]; for (int i = 0; i < cur.length; i++) { newArr[i] = cloneOne(cur[i]); } return newArr; } - public static CustomizationNeed cloneOne(CustomizationNeed cur) + public static FileCopyNeed cloneOne(FileCopyNeed cur) throws Exception { if (cur == null) { return null; } - return new CustomizationNeed( - cur.sourcePath, cur.destPath, cur.wasSent, 0); + return new FileCopyNeed( + cur.sourcePath, cur.destPath, cur.onImage, 0); } } diff --git a/service/service/java/source/src/org/globus/workspace/service/binding/vm/VirtualMachine.java b/service/service/java/source/src/org/globus/workspace/service/binding/vm/VirtualMachine.java index fe1091fe..23174746 100644 --- a/service/service/java/source/src/org/globus/workspace/service/binding/vm/VirtualMachine.java +++ b/service/service/java/source/src/org/globus/workspace/service/binding/vm/VirtualMachine.java @@ -46,7 +46,7 @@ public class VirtualMachine extends WorkspaceInstantiation { private VirtualMachinePartition[] partitions; - private CustomizationNeed[] customizationNeeds; + private FileCopyNeed[] fileCopyNeeds; private String credentialName; @@ -154,30 +154,30 @@ public void setCredentialName(String credentialName) { this.credentialName = credentialName; } - public synchronized void addCustomizationNeed(CustomizationNeed need) { - if (this.customizationNeeds == null) { - this.customizationNeeds = new CustomizationNeed[1]; - this.customizationNeeds[0] = need; + public synchronized void addFileCopyNeed(FileCopyNeed need) { + if (this.fileCopyNeeds == null) { + this.fileCopyNeeds = new FileCopyNeed[1]; + this.fileCopyNeeds[0] = need; } else { - final int curlen = this.customizationNeeds.length; - final CustomizationNeed[] src = this.customizationNeeds; - final CustomizationNeed[] dst = new CustomizationNeed[curlen+1]; + final int curlen = this.fileCopyNeeds.length; + final FileCopyNeed[] src = this.fileCopyNeeds; + final FileCopyNeed[] dst = new FileCopyNeed[curlen+1]; System.arraycopy(src, 0, dst, 0, curlen); dst[curlen] = need; - this.customizationNeeds = dst; + this.fileCopyNeeds = dst; } } - public synchronized CustomizationNeed[] getCustomizationNeeds() { - return this.customizationNeeds; + public synchronized FileCopyNeed[] getFileCopyNeeds() { + return this.fileCopyNeeds; } - public synchronized boolean isCustomizationAllDone() { - if (this.customizationNeeds == null) { + public synchronized boolean isFileCopyAllDone() { + if (this.fileCopyNeeds == null) { return true; } - for (int i = 0; i < this.customizationNeeds.length; i++) { - if (!this.customizationNeeds[i].isSent()) { + for (int i = 0; i < this.fileCopyNeeds.length; i++) { + if (!this.fileCopyNeeds[i].onImage()) { return false; } } @@ -268,8 +268,8 @@ public String toString() { } int custLen = 0; - if (this.customizationNeeds != null) { - custLen = this.customizationNeeds.length; + if (this.fileCopyNeeds != null) { + custLen = this.fileCopyNeeds.length; } boolean userDataPresent = this.mdUserData != null; @@ -293,8 +293,8 @@ public String toString() { } public boolean isPropagateStartOK() { - return this.customizationNeeds == null || - this.customizationNeeds.length <= 0; + return this.fileCopyNeeds == null || + this.fileCopyNeeds.length <= 0; } // part of the instantiation interface, nothing about VM deployment @@ -345,8 +345,8 @@ public static VirtualMachine cloneOne(final VirtualMachine vm) VirtualMachineDeployment.cloneOne(vm.deployment); } - newvm.customizationNeeds = - CustomizationNeed.cloneArray(vm.customizationNeeds); + newvm.fileCopyNeeds = + FileCopyNeed.cloneArray(vm.fileCopyNeeds); newvm.mdUserData = vm.mdUserData; newvm.credentialName = vm.credentialName; diff --git a/service/service/java/source/src/org/globus/workspace/service/impls/InstanceResourceImpl.java b/service/service/java/source/src/org/globus/workspace/service/impls/InstanceResourceImpl.java index 2de311ae..9229037a 100644 --- a/service/service/java/source/src/org/globus/workspace/service/impls/InstanceResourceImpl.java +++ b/service/service/java/source/src/org/globus/workspace/service/impls/InstanceResourceImpl.java @@ -31,7 +31,7 @@ import org.globus.workspace.service.binding.authorization.CreationAuthorizationCallout; import org.globus.workspace.service.binding.authorization.Decision; import org.globus.workspace.service.binding.authorization.PostTaskAuthorization; -import org.globus.workspace.service.binding.vm.CustomizationNeed; +import org.globus.workspace.service.binding.vm.FileCopyNeed; import org.globus.workspace.service.binding.vm.VirtualMachine; import org.nimbustools.api.repr.ShutdownTasks; @@ -321,11 +321,11 @@ public void setInitialVMMaccessOK(boolean accessOK) { this.vmmAccessOK = accessOK; } - public synchronized void newCustomizationNeed(CustomizationNeed need) { + public synchronized void newFileCopyNeed(FileCopyNeed need) { if (this.vm == null) { throw new IllegalStateException("vm is null"); } - this.vm.addCustomizationNeed(need); + this.vm.addFileCopyNeed(need); try { this.persistence.addCustomizationNeed(this.id, need); } catch (ManageException e) { diff --git a/service/service/java/source/src/org/globus/workspace/xen/XenUtil.java b/service/service/java/source/src/org/globus/workspace/xen/XenUtil.java index d55b9051..52de3c66 100644 --- a/service/service/java/source/src/org/globus/workspace/xen/XenUtil.java +++ b/service/service/java/source/src/org/globus/workspace/xen/XenUtil.java @@ -29,7 +29,7 @@ import org.globus.workspace.service.binding.vm.VirtualMachine; import org.globus.workspace.service.binding.vm.VirtualMachineDeployment; import org.globus.workspace.service.binding.vm.VirtualMachinePartition; -import org.globus.workspace.service.binding.vm.CustomizationNeed; +import org.globus.workspace.service.binding.vm.FileCopyNeed; import org.nimbustools.api.repr.vm.NIC; @@ -471,22 +471,24 @@ public static ArrayList constructCreateCommand(VirtualMachine vm, cmd.add(notificationInfo); } - final CustomizationNeed[] needs = vm.getCustomizationNeeds(); + final FileCopyNeed[] needs = vm.getFileCopyNeeds(); if (needs != null) { - if (!vm.isCustomizationAllDone()) { + if (!vm.isFileCopyAllDone()) { - boolean oneBeingSent = false; + boolean oneBeingSentToImage = false; final StringBuffer tasks = new StringBuffer("'"); for (int i = 0; i < needs.length; i++) { - if (!needs[i].isSent()) { + // Note that we don't copy needs with no destination path + // these are filecopies that are used at propagation time + if (!needs[i].onImage() && needs[i].destPath != null) { - if (oneBeingSent) { + if (oneBeingSentToImage) { tasks.append(WC_GROUP_SEPARATOR); } - oneBeingSent = true; + oneBeingSentToImage = true; tasks.append(needs[i].sourcePath) .append(WC_FIELD_SEPARATOR) @@ -501,7 +503,7 @@ public static ArrayList constructCreateCommand(VirtualMachine vm, tasks.append("'"); - if (oneBeingSent) { + if (oneBeingSentToImage) { cmd.add("--mnttasks"); cmd.add(tasks.toString()); } @@ -777,7 +779,7 @@ private static void filePush(VirtualMachine vm, throw new Exception("backendTargetDir needed but missing"); } - final CustomizationNeed[] needs = vm.getCustomizationNeeds(); + final FileCopyNeed[] needs = vm.getFileCopyNeeds(); if (needs == null || needs.length == 0) { logger.warn("file push: nothing to do?"); return; @@ -814,74 +816,4 @@ private static void filePush(VirtualMachine vm, WorkspaceUtil.runCommand(send, eventLog, traceLog, vm.getID().intValue()); } } - - public static void doCredentialPushLocalTarget(VirtualMachine vm, - String localDirectory, - String backendTargetDir, - boolean fake, - boolean eventLog, - boolean traceLog) throws Exception { - credentialPush(vm, localDirectory, backendTargetDir, fake, false, eventLog, traceLog); - } - - // todo: relieve need for loglevels - public static void doCredentialPushRemoteTarget(VirtualMachine vm, - String localDirectory, - String backendTargetDir, - boolean fake, - boolean eventLog, - boolean traceLog) throws Exception { - credentialPush(vm, localDirectory, backendTargetDir, fake, true, eventLog, traceLog); - } - - private static void credentialPush(VirtualMachine vm, - String localDirectory, - String backendTargetDir, - boolean fake, - boolean remoteTarget, - boolean eventLog, - boolean traceLog) throws Exception { - - if (localDirectory == null) { - throw new Exception("localDirectory needed but missing"); - } - if (backendTargetDir == null) { - throw new Exception("backendTargetDir needed but missing"); - } - - final String credentialPath = vm.getCredentialName(); - if (credentialPath == null) { - logger.warn("credential push: nothing to do?"); - return; - } - - final ArrayList cmd; - if (remoteTarget) { - cmd = SSHUtil.constructScpCommandPrefix(); - } else { - cmd = new ArrayList(4); - cmd.add("cp"); // hardcoded... TODO - cmd.add("-p"); - } - - final String path = localDirectory + "/" + credentialPath; - cmd.add(path); - - if (remoteTarget) { - cmd.addAll(SSHUtil.constructScpCommandSuffix( - vm.getNode(), backendTargetDir)); - } else { - cmd.add(backendTargetDir); - } - - final String[] send = (String[]) cmd.toArray(new String[cmd.size()]); - - if (fake) { - logger.debug("Would have run this for credential push: " + - WorkspaceUtil.printCmd(send)); - } else { - WorkspaceUtil.runCommand(send, eventLog, traceLog, vm.getID().intValue()); - } - } - } diff --git a/service/service/java/source/src/org/globus/workspace/xen/xenlocal/Start.java b/service/service/java/source/src/org/globus/workspace/xen/xenlocal/Start.java index e124a0ab..61aa7a02 100644 --- a/service/service/java/source/src/org/globus/workspace/xen/xenlocal/Start.java +++ b/service/service/java/source/src/org/globus/workspace/xen/xenlocal/Start.java @@ -19,8 +19,8 @@ import org.globus.workspace.WorkspaceException; import org.globus.workspace.PathConfigs; import org.globus.workspace.persistence.WorkspaceDatabaseException; +import org.globus.workspace.service.binding.vm.FileCopyNeed; import org.globus.workspace.service.binding.vm.VirtualMachine; -import org.globus.workspace.service.binding.vm.CustomizationNeed; import org.globus.workspace.xen.XenTask; import org.globus.workspace.xen.XenUtil; @@ -55,7 +55,7 @@ protected Exception preExecute(boolean fake) { // init would have thrown exception if null final VirtualMachine vm = this.ctx.getVm(); - final CustomizationNeed[] needs = vm.getCustomizationNeeds(); + final FileCopyNeed[] needs = vm.getFileCopyNeeds(); if (needs == null || needs.length == 0) { if (traceLog) { logger.debug("customization file push: nothing to do"); @@ -82,9 +82,9 @@ protected Exception preExecute(boolean fake) { final int vmid = vm.getID().intValue(); for (int i = 0; i < needs.length; i++) { try { - needs[i].setSent(true); + needs[i].setOnImage(true); this.ctx.getLocator().getPersistenceAdapter(). - setCustomizeTaskSent(vmid, needs[i]); + setFileCopyOnImage(vmid, needs[i]); } catch (WorkspaceDatabaseException e) { logger.error("", e); } diff --git a/service/service/java/source/src/org/globus/workspace/xen/xenssh/Propagate.java b/service/service/java/source/src/org/globus/workspace/xen/xenssh/Propagate.java index d3529148..d063c9f6 100644 --- a/service/service/java/source/src/org/globus/workspace/xen/xenssh/Propagate.java +++ b/service/service/java/source/src/org/globus/workspace/xen/xenssh/Propagate.java @@ -19,6 +19,8 @@ import org.globus.workspace.PathConfigs; import org.globus.workspace.WorkspaceException; import org.globus.workspace.cmdutils.SSHUtil; +import org.globus.workspace.persistence.WorkspaceDatabaseException; +import org.globus.workspace.service.binding.vm.FileCopyNeed; import org.globus.workspace.service.binding.vm.VirtualMachine; import org.globus.workspace.service.impls.site.PropagationAdapter; import org.globus.workspace.xen.XenTask; @@ -43,25 +45,6 @@ protected void init() throws WorkspaceException { final String credentialName = vm.getCredentialName(); if (credentialName != null) { - final boolean eventLog = this.ctx.lager().eventLog; - final boolean traceLog = this.ctx.lager().traceLog; - - final PathConfigs paths = this.ctx.getLocator().getPathConfigs(); - final String backendDirectory = paths.getBackendTempDirPath(); - final String localDirectory = paths.getLocalTempDirPath(); - - - try { - XenUtil.doCredentialPushRemoteTarget(vm, - localDirectory, - backendDirectory, - this.ctx.getLocator().getGlobalPolicies().isFake(), - eventLog, - traceLog); - } catch (Exception e) { - throw new WorkspaceException("Couldn't push credential to " + backendDirectory); - } - ssh.add("--prop-extra-args"); ssh.add("'credential=" + credentialName + "'"); } @@ -73,9 +56,42 @@ protected void init() throws WorkspaceException { } } - protected Exception preExecute() { - return _preExecute( - this.ctx.getLocator().getGlobalPolicies().isFake(), + protected Exception preExecute(boolean fake) { + + final boolean eventLog = this.ctx.lager().eventLog; + final boolean traceLog = this.ctx.lager().traceLog; + + if (traceLog) { + logger.trace("Beginning start pre-execute"); + } + + // init would have thrown exception if null + final VirtualMachine vm = this.ctx.getVm(); + + final FileCopyNeed[] needs = vm.getFileCopyNeeds(); + if (needs == null || needs.length == 0) { + if (traceLog) { + logger.debug("FileCopy push: nothing to do"); + } + return null; + } + + final PathConfigs paths = this.ctx.getLocator().getPathConfigs(); + final String backendDirectory = paths.getBackendTempDirPath(); + final String localDirectory = paths.getLocalTempDirPath(); + + try { + XenUtil.doFilePushRemoteTarget(vm, + localDirectory, + backendDirectory, + fake, + eventLog, + traceLog); + } catch (Exception e) { + return e; + } + + return _preExecute(fake, this.ctx.getLocator().getPropagationAdapter()); } diff --git a/service/service/java/source/src/org/globus/workspace/xen/xenssh/Start.java b/service/service/java/source/src/org/globus/workspace/xen/xenssh/Start.java index 1f753770..f1e36f19 100644 --- a/service/service/java/source/src/org/globus/workspace/xen/xenssh/Start.java +++ b/service/service/java/source/src/org/globus/workspace/xen/xenssh/Start.java @@ -20,8 +20,8 @@ import org.globus.workspace.PathConfigs; import org.globus.workspace.persistence.WorkspaceDatabaseException; import org.globus.workspace.cmdutils.SSHUtil; +import org.globus.workspace.service.binding.vm.FileCopyNeed; import org.globus.workspace.service.binding.vm.VirtualMachine; -import org.globus.workspace.service.binding.vm.CustomizationNeed; import org.globus.workspace.xen.XenTask; import org.globus.workspace.xen.XenUtil; @@ -47,46 +47,16 @@ protected void init() throws WorkspaceException { protected Exception preExecute(boolean fake) { - final boolean eventLog = this.ctx.lager().eventLog; - final boolean traceLog = this.ctx.lager().traceLog; - - if (traceLog) { - logger.trace("Beginning start pre-execute"); - } - - // init would have thrown exception if null final VirtualMachine vm = this.ctx.getVm(); - - final CustomizationNeed[] needs = vm.getCustomizationNeeds(); - if (needs == null || needs.length == 0) { - if (traceLog) { - logger.debug("customization file push: nothing to do"); - } - return null; - } - - final PathConfigs paths = this.ctx.getLocator().getPathConfigs(); - final String backendDirectory = paths.getBackendTempDirPath(); - final String localDirectory = paths.getLocalTempDirPath(); - - try { - XenUtil.doFilePushRemoteTarget(vm, - localDirectory, - backendDirectory, - fake, - eventLog, - traceLog); - } catch (Exception e) { - return e; - } + final FileCopyNeed[] needs = vm.getFileCopyNeeds(); // todo: do not like this concept (waiting for ORM overhaul) final int vmid = vm.getID().intValue(); for (int i = 0; i < needs.length; i++) { try { - needs[i].setSent(true); + needs[i].setOnImage(true); this.ctx.getLocator().getPersistenceAdapter(). - setCustomizeTaskSent(vmid, needs[i]); + setFileCopyOnImage(vmid, needs[i]); } catch (WorkspaceDatabaseException e) { logger.error("", e); } diff --git a/service/service/java/tests/suites/basic/home/services/share/nimbus/lib/workspace_service_derby_schema.sql b/service/service/java/tests/suites/basic/home/services/share/nimbus/lib/workspace_service_derby_schema.sql index f7b4a578..1936d486 100644 --- a/service/service/java/tests/suites/basic/home/services/share/nimbus/lib/workspace_service_derby_schema.sql +++ b/service/service/java/tests/suites/basic/home/services/share/nimbus/lib/workspace_service_derby_schema.sql @@ -117,14 +117,14 @@ PRIMARY KEY(association,ipaddress) ); -- --- Persistence for file customization tasks +-- Persistence for file copy tasks -CREATE TABLE vm_customization +CREATE TABLE file_copy ( vmid INT NOT NULL, sourcepath VARCHAR(32) NOT NULL, destpath VARCHAR(512) NOT NULL, -sent SMALLINT NOT NULL +on_image SMALLINT NOT NULL ); --