make multiple instances of scripted assignment use diff UUID

This commit is contained in:
Stephen Birarda 2014-02-24 11:56:14 -08:00
parent 4fc5444628
commit 9dc460bab4
3 changed files with 29 additions and 42 deletions

View file

@ -490,42 +490,47 @@ bool DomainServer::handleHTTPRequest(HTTPConnection* connection, const QString&
// this is a script upload - ask the HTTPConnection to parse the form data
QList<FormData> formData = connection->parseFormData();
// create an assignment for this saved script
Assignment* scriptAssignment = new Assignment(Assignment::CreateCommand, Assignment::AgentType);
// check how many instances of this assignment the user wants by checking the ASSIGNMENT-INSTANCES header
const QString ASSIGNMENT_INSTANCES_HEADER = "ASSIGNMENT-INSTANCES";
QByteArray assignmentInstancesValue = connection->requestHeaders().value(ASSIGNMENT_INSTANCES_HEADER.toLocal8Bit());
int numInstances = 1;
if (!assignmentInstancesValue.isEmpty()) {
// the user has requested a specific number of instances
// so set that on the created assignment
int numInstances = assignmentInstancesValue.toInt();
if (numInstances > 0) {
qDebug() << numInstances;
scriptAssignment->setNumberOfInstances(numInstances);
}
numInstances = assignmentInstancesValue.toInt();
}
const char ASSIGNMENT_SCRIPT_HOST_LOCATION[] = "resources/web/assignment";
QString newPath(ASSIGNMENT_SCRIPT_HOST_LOCATION);
newPath += "/";
// append the UUID for this script as the new filename, remove the curly braces
newPath += uuidStringWithoutCurlyBraces(scriptAssignment->getUUID());
// create a file with the GUID of the assignment in the script host locaiton
QFile scriptFile(newPath);
scriptFile.open(QIODevice::WriteOnly);
scriptFile.write(formData[0].second);
qDebug("Saved a script for assignment at %s", qPrintable(newPath));
for (int i = 0; i < numInstances; i++) {
// create an assignment for this saved script
Assignment* scriptAssignment = new Assignment(Assignment::CreateCommand, Assignment::AgentType);
QString newPath(ASSIGNMENT_SCRIPT_HOST_LOCATION);
newPath += "/";
// append the UUID for this script as the new filename, remove the curly braces
newPath += uuidStringWithoutCurlyBraces(scriptAssignment->getUUID());
// create a file with the GUID of the assignment in the script host locaiton
QFile scriptFile(newPath);
scriptFile.open(QIODevice::WriteOnly);
scriptFile.write(formData[0].second);
qDebug("Saved a script for assignment at %s", qPrintable(newPath));
// add the script assigment to the assignment queue
_assignmentQueue.enqueue(SharedAssignmentPointer(scriptAssignment));
}
// respond with a 200 code for successful upload
connection->respond(HTTPConnection::StatusCode200);
// add the script assigment to the assignment queue
_assignmentQueue.enqueue(SharedAssignmentPointer(scriptAssignment));
}
} else if (connection->requestOperation() == QNetworkAccessManager::DeleteOperation) {
if (path.startsWith(URI_NODE)) {
@ -639,14 +644,7 @@ SharedAssignmentPointer DomainServer::deployableAssignmentForRequest(const Assig
if (assignment->getType() == Assignment::AgentType) {
// if there is more than one instance to send out, simply decrease the number of instances
if (assignment->getNumberOfInstances() == 1) {
return _assignmentQueue.takeAt(sharedAssignment - _assignmentQueue.begin());
} else {
assignment->decrementNumberOfInstances();
return *sharedAssignment;
}
return _assignmentQueue.takeAt(sharedAssignment - _assignmentQueue.begin());
} else {
// remove the assignment from the queue
SharedAssignmentPointer deployableAssignment = _assignmentQueue.takeAt(sharedAssignment

View file

@ -45,7 +45,6 @@ Assignment::Assignment() :
_type(Assignment::AllTypes),
_pool(),
_location(Assignment::LocalLocation),
_numberOfInstances(1),
_payload()
{
@ -57,7 +56,6 @@ Assignment::Assignment(Assignment::Command command, Assignment::Type type, const
_type(type),
_pool(pool),
_location(location),
_numberOfInstances(1),
_payload()
{
if (_command == Assignment::CreateCommand) {
@ -69,7 +67,6 @@ Assignment::Assignment(Assignment::Command command, Assignment::Type type, const
Assignment::Assignment(const QByteArray& packet) :
_pool(),
_location(GlobalLocation),
_numberOfInstances(1),
_payload()
{
PacketType packetType = packetTypeForPacket(packet);
@ -99,7 +96,6 @@ Assignment::Assignment(const Assignment& otherAssignment) {
_type = otherAssignment._type;
_location = otherAssignment._location;
_pool = otherAssignment._pool;
_numberOfInstances = otherAssignment._numberOfInstances;
_payload = otherAssignment._payload;
}
@ -117,8 +113,6 @@ void Assignment::swap(Assignment& otherAssignment) {
swap(_type, otherAssignment._type);
swap(_location, otherAssignment._location);
swap(_pool, otherAssignment._pool);
swap(_numberOfInstances, otherAssignment._numberOfInstances);
swap(_payload, otherAssignment._payload);
}

View file

@ -79,11 +79,7 @@ public:
void setPool(const QString& pool) { _pool = pool; };
const QString& getPool() const { return _pool; }
int getNumberOfInstances() const { return _numberOfInstances; }
void setNumberOfInstances(int numberOfInstances) { _numberOfInstances = numberOfInstances; }
void decrementNumberOfInstances() { --_numberOfInstances; }
const char* getTypeName() const;
// implement parseData to return 0 so we can be a subclass of NodeData
@ -99,7 +95,6 @@ protected:
Assignment::Type _type; /// the type of the assignment, defines what the assignee will do
QString _pool; /// the destination pool for this assignment
Assignment::Location _location; /// the location of the assignment, allows a domain to preferentially use local ACs
int _numberOfInstances; /// the number of instances of this assignment
QByteArray _payload; /// an optional payload attached to this assignment, a maximum for 1024 bytes will be packed
};