Skip to content
This repository has been archived by the owner on Aug 30, 2024. It is now read-only.

Commit

Permalink
DescribeBundleTasks back-end implementation nearly complete (still ne…
Browse files Browse the repository at this point in the history
…ed to implement logic in NC)
  • Loading branch information
root committed Mar 31, 2010
1 parent 6c7aed1 commit 2810b9a
Show file tree
Hide file tree
Showing 17 changed files with 223 additions and 93 deletions.
4 changes: 2 additions & 2 deletions cluster/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ generated/stubs: $(CCWSDL)

server: $(SERVICE_SO)

$(SERVICE_SO): generated/stubs ../storage/storage.o server-marshal.o handlers.o $(AXIS2C_HOME)/lib/libaxutil.so
$(CC) -shared generated/*.o server-marshal.o handlers.o $(SCLIBS) $(NCLIBS) $(VNLIBS) $(WSSECLIBS) $(CC_LIBS) -o $(SERVICE_SO)
$(SERVICE_SO): generated/stubs ../storage/storage.o server-marshal.o handlers.o $(AXIS2C_HOME)/lib/libaxutil.so windows-cc.o ../util/windows-bundle.o
$(CC) -shared generated/*.o server-marshal.o handlers.o windows-cc.o ../util/windows-bundle.o $(SCLIBS) $(NCLIBS) $(VNLIBS) $(WSSECLIBS) $(CC_LIBS) -o $(SERVICE_SO)

client: $(CLIENT)_full $(CLIENTKILLALL)

Expand Down
5 changes: 5 additions & 0 deletions cluster/cc-client-marshal-adb.c
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,12 @@ int cc_describeBundleTasks(char **instIds, int instIdsLen, axutil_env_t *env, ax
if (status == AXIS2_FALSE) {
printf("operation fault '%s'\n", adb_describeBundleTasksResponseType_get_statusMessage(dirt, env));
} else {
adb_bundleTaskType_t *bundle;
printf("operation success\n");
for (i=0; i<adb_describeBundleTasksResponseType_sizeof_bundleTasks(dirt, env); i++) {
bundle = adb_describeBundleTasksResponseType_get_bundleTasks_at(dirt, env, i);
printf("BUNDLE %d: %s %s %s\n", i, adb_bundleTaskType_get_instanceId(bundle, env), adb_bundleTaskType_get_state(bundle, env), adb_bundleTaskType_get_manifest(bundle, env));
}
}
}
return 0;
Expand Down
103 changes: 43 additions & 60 deletions cluster/handlers.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ permission notice:
#include "data.h"
#include "client-marshal.h"

#include <windows-cc.h>

#define SUPERUSER "eucalyptus"

// local globals
Expand All @@ -103,6 +105,8 @@ vnetConfig *vnetconfig=NULL;
sem_t *locks[ENDLOCK] = {NULL, NULL, NULL, NULL, NULL, NULL};
int mylocks[ENDLOCK] = {0,0,0,0,0,0};

ccBundleCache *bundleCache=NULL;

int doBundleInstance(ncMetadata *ccMeta, char *instanceId, char *bucketName, char *filePrefix, char *S3URL, char *userPublicKey, char *cloudPublicKey) {
int i, j, rc, start = 0, stop = 0, ret=0;
ccInstance *myInstance;
Expand Down Expand Up @@ -200,8 +204,8 @@ int doBundleInstance(ncMetadata *ccMeta, char *instanceId, char *bucketName, cha
*/
}

int doDescribeBundleTasks(ncMetadata *ccMeta, char **instIds, int instIdsLen) {
int i, j, k, rc, start = 0, stop = 0, ret=0;
int doDescribeBundleTasks(ncMetadata *ccMeta, char **instIds, int instIdsLen, bundleTask **outBundleTasks, int *outBundleTasksLen) {
int i, j, k, rc, start = 0, stop = 0, ret=0, count=0;
ccInstance *myInstance;
ncStub *ncs;
time_t op_start, op_timer;
Expand All @@ -218,70 +222,35 @@ int doDescribeBundleTasks(ncMetadata *ccMeta, char **instIds, int instIdsLen) {
logprintfl(EUCAINFO, "DescribeBundleTasks(): called\n");
logprintfl(EUCADEBUG, "DescribeBundleTasks(): params: userId=%s, instIdsLen=%d\n", SP(ccMeta->userId), instIdsLen);

i = j = 0;
myInstance = NULL;

if (!instIds) {
logprintfl(EUCAERROR, "DescribeBundleTasks(): bad input params\n");
return(1);
}

for (k=0; k<instIdsLen; k++) {
instanceId = instIds[k];
sem_mywait(NCCALL);
sem_mywait(RESCACHE);
*outBundleTasks = NULL;
*outBundleTasksLen = 0;

rc = find_instanceCacheId(instanceId, &myInstance);
if (!rc) {
// found the instance in the cache
if (myInstance) {
start = myInstance->ncHostIdx;
stop = start+1;
free(myInstance);
}
} else {
start = 0;
stop = resourceCache->numResources;
sem_mywait(BUNDLECACHE);
count=0;
if (bundleCache->numBundles) {
*outBundleTasks = malloc(sizeof(bundleTask) * bundleCache->numBundles);
if (!*outBundleTasks) {
logprintfl(EUCAFATAL, "doDescribeBundleTasks(): out of memory!\n");
unlock_exit(1);
}

for (j=start; j<stop; j++) {
// read the instance ids
logprintfl(EUCAINFO,"DescribeBundleTasks(): calling describe bundle tasks (%s) on (%s)\n", instanceId, resourceCache->resources[j].hostname);
if (1) {
int pid, status;
pid = fork();
if (pid == 0) {
ret=0;
ncs = ncStubCreate(resourceCache->resources[j].ncURL, NULL, NULL);
if (config->use_wssec) {
rc = InitWSSEC(ncs->env, ncs->stub, config->policyFile);
}
rc = 0;
rc = ncDescribeBundleTasksStub(ncs, ccMeta, instIds, instIdsLen);
if (!rc) {
ret = 0;
} else {
ret = 1;
}
exit(ret);
} else {
op_timer = OP_TIMEOUT - (time(NULL) - op_start);
rc = timewait(pid, &status, minint(op_timer / ((stop-start) - (j - start)), OP_TIMEOUT_PERNODE));
rc = WEXITSTATUS(status);
logprintfl(EUCADEBUG,"\tcall complete (pid/rc): %d/%d\n", pid, rc);

for (i=0; i<MAXBUNDLES; i++) {
if (bundleCache->cacheState[i] == BUNDLEVALID) {
memcpy( &((*outBundleTasks)[count]), &(bundleCache->bundles[i]), sizeof(bundleTask));
count++;
if (count > bundleCache->numBundles) {
logprintfl(EUCAWARN, "doDescribeBundleTasks(): found more bundles than reported by numBundles, will only report a subset of bundles\n");
count=0;
}
}

if (!rc) {
ret = 0;
} else {
logprintfl(EUCAERROR, "DescribeBundleTasks(): call to NC failed: instanceId=%s\n", instanceId);
ret = 1;
}
}

sem_mypost(RESCACHE);
sem_mypost(NCCALL);
*outBundleTasksLen = bundleCache->numBundles;
}
sem_mypost(BUNDLECACHE);

for (i=0; i< (*outBundleTasksLen) ; i++) {
logprintfl(EUCADEBUG, "DescribeBundleTasks(): returning: instanceId=%s, state=%s, manifest=%s\n", (*outBundleTasks)[i].instanceId, (*outBundleTasks)[i].state, (*outBundleTasks)[i].manifest);
}

logprintfl(EUCADEBUG,"DescribeBundleTasks(): done.\n");
Expand Down Expand Up @@ -2362,6 +2331,10 @@ void *monitor_thread(void *in) {
logprintfl(EUCAWARN, "monitor_thread(): call to refresh_instances() failed in monitor thread\n");
}

rc = refresh_bundleTasks(&ccMeta, 60, 1);
if (rc) {
logprintfl(EUCAWARN, "monitor_thread(): call to refresh_bundleTasks() failed in monitor thread\n");
}

sem_mywait(CONFIG);
if (config->kick_dhcp) {
Expand Down Expand Up @@ -2502,6 +2475,16 @@ int init_thread(void) {
exit(1);
}
}

if (bundleCache == NULL) {
rc = setup_shared_buffer((void **)&bundleCache, "/eucalyptusCCBundleCache", sizeof(ccBundleCache), &(locks[BUNDLECACHE]), "/eucalyptusCCBundleCacheLock", SHARED_FILE);
if (rc != 0) {
fprintf(stderr, "init_thread(): Cannot set up shared memory region for ccBundleCache, exiting...\n");
sem_mypost(INIT);
exit(1);
}
}

sem_mypost(INIT);
thread_init=1;
}
Expand Down
4 changes: 2 additions & 2 deletions cluster/handlers.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ permission notice:
#define OP_TIMEOUT_PERNODE 20

enum {SHARED_MEM, SHARED_FILE};
enum {INIT, CONFIG, VNET, INSTCACHE, RESCACHE, NCCALL, ENDLOCK};
enum {INIT, CONFIG, VNET, INSTCACHE, RESCACHE, NCCALL, BUNDLECACHE, ENDLOCK};

typedef struct instance_t {
char instanceId[16];
Expand Down Expand Up @@ -170,7 +170,7 @@ int doAttachVolume(ncMetadata *ccMeta, char *volumeId, char *instanceId, char *r
int doDetachVolume(ncMetadata *ccMeta, char *volumeId, char *instanceId, char *remoteDev, char *localDev, int force);

int doBundleInstance(ncMetadata *ccMeta, char *instanceId, char *bucketName, char *filePrefix, char *S3URL, char *userPublicKey, char *cloudPublicKey);
int doDescribeBundleTasks(ncMetadata *ccMeta, char **instIds, int instIdsLen);
int doDescribeBundleTasks(ncMetadata *ccMeta, char **instIds, int instIdsLen, bundleTask **outBundleTasks, int *outBundleTasksLen);

int doAssignAddress(ncMetadata *ccMeta, char *src, char *dst);
int doUnassignAddress(ncMetadata *ccMeta, char *src, char *dst);
Expand Down
26 changes: 22 additions & 4 deletions cluster/server-marshal.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,9 @@ adb_DescribeBundleTasksResponse_t *DescribeBundleTasksMarshal(adb_DescribeBundle
char statusMessage[256];
char **instIds=NULL, *cid;
ncMetadata ccMeta;

bundleTask *outBundleTasks=NULL;
int outBundleTasksLen=0;

bit = adb_DescribeBundleTasks_get_DescribeBundleTasks(describeBundleTasks, env);

ccMeta.correlationId = adb_describeBundleTasksType_get_correlationId(bit, env);
Expand All @@ -242,18 +244,31 @@ adb_DescribeBundleTasksResponse_t *DescribeBundleTasksMarshal(adb_DescribeBundle
for (i=0; i<instIdsLen; i++) {
instIds[i] = adb_describeBundleTasksType_get_instanceIds_at(bit, env, i);
}

birt = adb_describeBundleTasksResponseType_create(env);

status = AXIS2_TRUE;
if (!DONOTHING) {
rc = doDescribeBundleTasks(&ccMeta, instIds, instIdsLen);
rc = doDescribeBundleTasks(&ccMeta, instIds, instIdsLen, &outBundleTasks, &outBundleTasksLen);
if (instIds) free(instIds);
if (rc) {
logprintf("ERROR: doDescribeBundleTasks() returned FAIL\n");
status = AXIS2_FALSE;
snprintf(statusMessage, 255, "ERROR");
} else {
for (i=0; i<outBundleTasksLen; i++) {
adb_bundleTaskType_t *bundle;
bundle = adb_bundleTaskType_create(env);
adb_bundleTaskType_set_instanceId(bundle, env, outBundleTasks[i].instanceId);
adb_bundleTaskType_set_state(bundle, env, outBundleTasks[i].state);
adb_bundleTaskType_set_manifest(bundle, env, outBundleTasks[i].manifest);

adb_describeBundleTasksResponseType_add_bundleTasks(birt, env, bundle);
}
if (outBundleTasks) free(outBundleTasks);
}
}

birt = adb_describeBundleTasksResponseType_create(env);
adb_describeBundleTasksResponseType_set_return(birt, env, status);
if (status == AXIS2_FALSE) {
adb_describeBundleTasksResponseType_set_statusMessage(birt, env, statusMessage);
Expand Down Expand Up @@ -983,7 +998,10 @@ int ccInstanceUnmarshal(adb_ccInstanceType_t *dst, ccInstance *src, const axutil
adb_ccInstanceType_set_serviceTag(dst, env, src->serviceTag);
adb_ccInstanceType_set_userData(dst, env, src->userData);
adb_ccInstanceType_set_launchIndex(dst, env, src->launchIndex);
adb_ccInstanceType_set_platform(dst, env, src->platform);
if (src->platform && strlen(src->platform)) {
logprintfl(EUCADEBUG, "HALO: %s %d\n", src->platform, strlen(src->platform));
adb_ccInstanceType_set_platform(dst, env, src->platform);
}
for (i=0; i<64; i++) {
if (src->groupNames[i][0] != '\0') {
adb_ccInstanceType_add_groupNames(dst, env, src->groupNames[i]);
Expand Down
5 changes: 4 additions & 1 deletion node/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ server: $(SERVICE_SO)
../util/euca_auth.o: ../util/euca_auth.c ../util/data.h ../util/eucalyptus.h
make -C ../util

$(SERVICE_SO): generated/stubs ../storage/storage.o ../storage/walrus.o ../net/vnetwork.o ../util/misc.o ../util/data.o server-marshal.o handlers.o $(NC_HANDLERS) $(AXIS2C_HOME)/lib/libaxutil.so ../util/eucalyptus.h ../util/euca_auth.o
../util/windows-bundle.o: ../util/windows-bundle.c ../util/windows-bundle.h
make -C ../util

$(SERVICE_SO): generated/stubs ../storage/storage.o ../storage/walrus.o ../net/vnetwork.o ../util/misc.o ../util/data.o ../util/windows-bundle.o server-marshal.o handlers.o $(NC_HANDLERS) $(AXIS2C_HOME)/lib/libaxutil.so ../util/eucalyptus.h ../util/euca_auth.o
$(CC) -o $(SERVICE_SO) -shared $(NC_LIBS) generated/adb_*.o generated/axis2*_skel_*.o server-marshal.o handlers.o $(NC_HANDLERS) ../storage/*.o ../net/*.o ../util/*.o

clientlib: generated/stubs ../util/data.o client-marshal-adb.o
Expand Down
16 changes: 11 additions & 5 deletions node/NCclient.c
Original file line number Diff line number Diff line change
Expand Up @@ -372,12 +372,18 @@ int main (int argc, char **argv)
instIds[1] = malloc(sizeof(char) * 32);
instIds[2] = malloc(sizeof(char) * 32);
instIds[3] = malloc(sizeof(char) * 32);
snprintf(instIds[0], 32, "i-12345678");
snprintf(instIds[1], 32, "i-12345678");
snprintf(instIds[2], 32, "i-12345678");
snprintf(instIds[3], 32, "i-12345678");
snprintf(instIds[0], 32, "i-12345675");
snprintf(instIds[1], 32, "i-12345674");
snprintf(instIds[2], 32, "i-12345673");
snprintf(instIds[3], 32, "i-12345672");
instIdsLen=4;
int rc = ncDescribeBundleTasksStub(stub, &meta, instIds, instIdsLen);
bundleTask **outBundleTasks=NULL;
int outBundleTasksLen=0;
int i, rc;
rc = ncDescribeBundleTasksStub(stub, &meta, instIds, instIdsLen, &outBundleTasks, &outBundleTasksLen);
for (i=0; i<outBundleTasksLen; i++) {
printf("BUNDLE %d: %s %s %s\n", i, outBundleTasks[i]->instanceId, outBundleTasks[i]->state, outBundleTasks[i]->manifest);
}
} else if (!strcmp(command, "terminateInstance")) {
CHECK_PARAM(instance_id, "instance ID");

Expand Down
17 changes: 13 additions & 4 deletions node/client-marshal-adb.c
Original file line number Diff line number Diff line change
Expand Up @@ -724,13 +724,12 @@ int ncBundleInstanceStub (ncStub *st, ncMetadata *meta, char *instanceId, char *
return status;
}

int ncDescribeBundleTasksStub (ncStub *st, ncMetadata *meta, char **instIds, int instIdsLen) {
int ncDescribeBundleTasksStub (ncStub *st, ncMetadata *meta, char **instIds, int instIdsLen, bundleTask ***outBundleTasks, int *outBundleTasksLen) {
int i;
axutil_env_t * env = st->env;
axis2_stub_t * stub = st->stub;
adb_ncDescribeBundleTasks_t * input = adb_ncDescribeBundleTasks_create (env);
adb_ncDescribeBundleTasksType_t * request = adb_ncDescribeBundleTasksType_create (env);

// set standard input fields
if (meta) {
adb_ncDescribeBundleTasksType_set_correlationId (request, env, meta->correlationId);
Expand All @@ -747,7 +746,7 @@ int ncDescribeBundleTasksStub (ncStub *st, ncMetadata *meta, char **instIds, int
int status = 0;
{ // do it
adb_ncDescribeBundleTasksResponse_t * output = axis2_stub_op_EucalyptusNC_ncDescribeBundleTasks (stub, env, input);

if (!output) {
logprintfl (EUCAERROR, "ERROR: DescribeBundleTasks" NULL_ERROR_MSG);
status = -1;
Expand All @@ -757,7 +756,17 @@ int ncDescribeBundleTasksStub (ncStub *st, ncMetadata *meta, char **instIds, int
if ( adb_ncDescribeBundleTasksResponseType_get_return(response, env) == AXIS2_FALSE ) {
logprintfl (EUCAERROR, "ERROR: DescribeBundleTasks returned an error\n");
status = 1;
}
}
*outBundleTasksLen = adb_ncDescribeBundleTasksResponseType_sizeof_bundleTasks(response, env);
*outBundleTasks = malloc(sizeof(bundleTask *) * *outBundleTasksLen);
for (i=0; i<*outBundleTasksLen; i++) {
adb_bundleTaskType_t *bundle;
bundle = adb_ncDescribeBundleTasksResponseType_get_bundleTasks_at(response, env, i);
(*outBundleTasks)[i] = malloc(sizeof(bundleTask));
snprintf( (*outBundleTasks)[i]->instanceId, CHAR_BUFFER_SIZE, "%s", adb_bundleTaskType_get_instanceId(bundle, env));
snprintf( (*outBundleTasks)[i]->state, CHAR_BUFFER_SIZE, "%s", adb_bundleTaskType_get_state(bundle, env));
snprintf( (*outBundleTasks)[i]->manifest, 32768, "%s", adb_bundleTaskType_get_manifest(bundle, env));
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion node/client-marshal-local.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ int ncDescribeInstancesStub (ncStub *st, ncMetadata *meta, char **instIds, int i
int ncBundleInstanceStub (ncStub *stub, ncMetadata *meta, char *instanceId, char *bucketName, char *filePrefix, char *S3URL, char *userPublicKey, char *cloudPublicKey) {
return(0);
}
int ncDescribeBundleTasksStub (ncStub *stub, ncMetadata *meta, char **instIds, int instIdsLen) {
int ncDescribeBundleTasksStub (ncStub *stub, ncMetadata *meta, char **instIds, int instIdsLen, bundleTask ***outBundleTasks, int *outBundleTasksLen) {
return(0);
}

Expand Down
4 changes: 3 additions & 1 deletion node/client-marshal.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ permission notice:
#include "axis2_stub_EucalyptusNC.h" /* for axis2_ and axutil_ defs */
#include "data.h" /* for eucalyptus defs */

#include <windows-bundle.h>

typedef struct ncStub_t {
axutil_env_t * env;
axis2_char_t * client_home;
Expand All @@ -84,6 +86,6 @@ int ncPowerDownStub (ncStub *st, ncMetadata *meta);
int ncAttachVolumeStub (ncStub *stub, ncMetadata *meta, char *instanceId, char *volumeId, char *remoteDev, char *localDev);
int ncDetachVolumeStub (ncStub *stub, ncMetadata *meta, char *instanceId, char *volumeId, char *remoteDev, char *localDev, int force);
int ncBundleInstanceStub (ncStub *stub, ncMetadata *meta, char *instanceId, char *bucketName, char *filePrefix, char *S3URL, char *userPublicKey, char *cloudPublicKey);
int ncDescribeBundleTasksStub (ncStub *stub, ncMetadata *meta, char **instIds, int instIdsLen);
int ncDescribeBundleTasksStub (ncStub *stub, ncMetadata *meta, char **instIds, int instIdsLen, bundleTask ***outBundleTasks, int *outBundleTasksLen);

#endif
10 changes: 5 additions & 5 deletions node/handlers.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ permission notice:
#include <storage.h>
#include <eucalyptus.h>

#include <windows-bundle.h>

#define MONITORING_PERIOD (5)

/* used by lower level handlers */
Expand Down Expand Up @@ -1147,19 +1149,17 @@ int doBundleInstance (ncMetadata *meta, char *instanceId, char *bucketName, char
return ret;
}

int doDescribeBundleTasks (ncMetadata *meta, char **instIds, int instIdsLen)
int doDescribeBundleTasks (ncMetadata *meta, char **instIds, int instIdsLen, bundleTask ***outBundleTasks, int *outBundleTasksLen)
{
int ret;

if (init())
return 1;

logprintfl (EUCAINFO, "doDescribeBundleTasks() invoked (instIdsLen=%d)\n", instIdsLen);

if (nc_state.H->doDescribeBundleTasks)
ret = nc_state.H->doDescribeBundleTasks (&nc_state, meta, instIds, instIdsLen);
ret = nc_state.H->doDescribeBundleTasks (&nc_state, meta, instIds, instIdsLen, outBundleTasks, outBundleTasksLen);
else
ret = nc_state.D->doDescribeBundleTasks (&nc_state, meta, instIds, instIdsLen);
ret = nc_state.D->doDescribeBundleTasks (&nc_state, meta, instIds, instIdsLen, outBundleTasks, outBundleTasksLen);

return ret;
}
Expand Down
Loading

0 comments on commit 2810b9a

Please sign in to comment.