Skip to content
This repository has been archived by the owner on Sep 23, 2020. It is now read-only.

Commit

Permalink
Refactor CustomizationNeed to FileCopyNeed.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
oldpatricka committed Dec 7, 2010
1 parent f2288e0 commit 7b64f30
Show file tree
Hide file tree
Showing 20 changed files with 203 additions and 267 deletions.
Expand Up @@ -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
);

--
Expand Down Expand Up @@ -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

Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
Expand Down
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down
Expand Up @@ -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 =
Expand All @@ -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(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
Expand All @@ -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, " +
Expand Down Expand Up @@ -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=? " +
Expand Down Expand Up @@ -203,27 +203,27 @@ 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,
SQL_DELETE_GROUP_RESOURCE,
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,
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -1430,7 +1430,7 @@ public void load(int id, InstanceResource resource)
}
} else {
do {
vm.addCustomizationNeed(
vm.addFileCopyNeed(
VirtualMachinePersistenceUtil.getNeed(rs));
} while (rs.next());
}
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand All @@ -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];
Expand Down Expand Up @@ -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);
}
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Expand Up @@ -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;
Expand All @@ -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;
}
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Up @@ -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;
Expand Down Expand Up @@ -55,17 +56,30 @@ 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();
} catch (Exception e) {
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);
}
}

0 comments on commit 7b64f30

Please sign in to comment.