Ejemplo n.º 1
0
/* ACKJOB jobid_1 jobid_2 ... jobid_N
 *
 * Set job state as acknowledged, if the job does not exist creates a
 * fake job just to hold the acknowledge.
 *
 * As a result of a job being acknowledged, the system tries to garbage
 * collect it, that is, to remove the job from every node of the system
 * in order to both avoid multiple deliveries of the same job, and to
 * release resources.
 *
 * If a job was already acknowledged, the ACKJOB command still has the
 * effect of forcing a GC attempt ASAP.
 *
 * The command returns the number of jobs already known and that were
 * already not in the ACKED state.
 */
void ackjobCommand(client *c) {
    int j, known = 0;

    if (validateJobIDs(c,c->argv+1,c->argc-1) == C_ERR) return;

    /* Perform the appropriate action for each job. */
    for (j = 1; j < c->argc; j++) {
        job *job = lookupJob(c->argv[j]->ptr);
        /* Case 1: No such job. Create one just to hold the ACK. However
         * if the cluster is composed by a single node we are sure the job
         * does not exist in the whole cluster, so do this only if the
         * cluster size is greater than one. */
        if (job == NULL && server.cluster->size > 1 && !myselfLeaving()) {
            char *id = c->argv[j]->ptr;
            int ttl = getRawTTLFromJobID(id);

            /* TTL is even for "at most once" jobs. In this case we
             * don't need to create a dummy hack. */
            if (ttl & 1) {
                job = createJob(id,JOB_STATE_ACKED,0,0);
                setJobTTLFromID(job);
                serverAssert(registerJob(job) == C_OK);
            }
        }
        /* Case 2: Job exists and is not acknowledged. Change state. */
        else if (job && job->state != JOB_STATE_ACKED) {
            dequeueJob(job); /* Safe to call if job is not queued. */
            acknowledgeJob(job);
            known++;
        }
        /* Anyway... start a GC attempt on the acked job. */
        if (job) tryJobGC(job);
    }
    addReplyLongLong(c,known);
}
Ejemplo n.º 2
0
int main(int argc, char **argv)
{
    int i;
    int n;
    NodePtr node;
    JobPtr job;
    ListPtr list;

    if (argc != 2) {
        fprintf(stderr, "Usage: %s <list size> \n",argv[0]);
        exit(1);
    }
    n = atoi(argv[1]);

    list = createList();
    for (i=0; i<n; i++) {
        job = createJob(i, "cmd args");
        node = createNode(job);
        addAtFront(list, node);
    }

    printList(list);
    reverseList(list);
    printList(list);
    reverseList(list);
    printList(list);

    exit(0);
}
Ejemplo n.º 3
0
Job createRandomJob() {
	int numberOfPhases = generateRandom(MIN_NUMBER_OF_PHASES, MAX_NUMBER_OF_PHASES);
	Phase phases[numberOfPhases];
	int i = 0;
	PhaseType type;

	for (i = 0; i < numberOfPhases; i++) {
		int duration = generateRandom(1, MAX_DURATION);
		Phase phase;
		phase.duration = duration;
		if (type == CPU_PHASE) {
			type = IO_PHASE;
		} else if (type == IO_PHASE) {
			type = CPU_PHASE;
		} else {
			type = duration % 2 == 0 ? CPU_PHASE : IO_PHASE;
		}
		phase.type = type;
		phases[i] = phase;
	}

	Job job = createJob(phases, numberOfPhases);
	printf("Created Job %d\n", job.id);
	job.printJob(&job);

	return job;
}
Ejemplo n.º 4
0
QAbstractAnimationJob *QQuickAnimator::transition(QQuickStateActions &actions,
                                                  QQmlProperties &modified,
                                                  TransitionDirection direction,
                                                  QObject *defaultTarget)
{
    Q_D(QQuickAnimator);

    if (d->defaultProperty.isValid() && propertyName() != d->defaultProperty.name()) {
        qDebug() << Q_FUNC_INFO << "property name conflict...";
        return 0;
    }

    // The animation system cannot handle backwards uncontrolled animations.
    if (direction == Backward)
        return 0;

    QQuickAnimatorJob *job = createJob();
    if (!job)
        return 0;

    d->apply(job, propertyName(), actions, modified, defaultTarget);

    if (!job->target()) {
        delete job;
        return 0;
    }

    return job;
}
Ejemplo n.º 5
0
int main(int argc, char **argv)
{	
	int i;

	NodePtr node;
	JobPtr job;
	ListPtr list;

	process_cmdline_arguments(argc, argv);

	if (state->restart) {
			fprintf(stderr, "%s: Attempting to restart from checkpoint.\n", program);
			list = start_from_checkpoint();
	} else {
		list = createList();
		for (i=0; i<state->n; i++)
		{
			job = createJob(i, "args");
			node = createNode(job);
			addAtFront(list, node);
		}
	}

	runRandomTests(state, list);

	if (DEBUG > 0)
		printList(list);

	remove(stateFile);
	remove(state->saveFile);
	exit(0);
}
Ejemplo n.º 6
0
NodePtr createAndSetNode(int *jobNumber, int backgroundJob, char* bufCopy, int isBackground){
     JobPtr job = createJob((int)backgroundJob, bufCopy, *jobNumber);
	 if(isBackground == 1) job->background = 1;
	 (*jobNumber)++;
	 NodePtr node = createNode(job);
	 setNode(node);
	 return node;
}
Ejemplo n.º 7
0
void metalink::start()
{
    kDebug(5001) << "metalink::start";
    if(!m_copyjob)
        createJob();

    setStatus(Job::Running, i18nc("transfer state: connecting", "Connecting...."), SmallIcon("connect-creating"));
    setTransferChange(Tc_Status, true);
}
Ejemplo n.º 8
0
void OwncloudPropagator::start(const SyncFileItemVector& _syncedItems)
{
    /* This builds all the job needed for the propagation.
     * Each directories is a PropagateDirectory job, which contains the files in it.
     * In order to do that we sort the items by destination. and loop over it. When we enter a
     * directory, we can create the directory job and push it on the stack. */
    SyncFileItemVector items = _syncedItems;
    std::sort(items.begin(), items.end());
    _rootJob.reset(new PropagateDirectory(this));
    QStack<QPair<QString /* directory name */, PropagateDirectory* /* job */> > directories;
    directories.push(qMakePair(QString(), _rootJob.data()));
    QVector<PropagatorJob*> directoriesToRemove;
    QString removedDirectory;
    foreach(const SyncFileItem &item, items) {
        if (item._instruction == CSYNC_INSTRUCTION_REMOVE
            && !removedDirectory.isEmpty() && item._file.startsWith(removedDirectory)) {
            //already taken care of.  (by the removal of the parent directory)
            continue;
        }

        while (!item.destination().startsWith(directories.top().first)) {
            directories.pop();
        }

        if (item._isDirectory) {
            PropagateDirectory *dir = new PropagateDirectory(this, item);
            dir->_firstJob.reset(createJob(item));
            if (item._instruction == CSYNC_INSTRUCTION_REMOVE) {
                //We do the removal of directories at the end
                directoriesToRemove.append(dir);
                removedDirectory = item._file + "/";
            } else {
                directories.top().second->append(dir);
            }
            directories.push(qMakePair(item.destination() + "/" , dir));
        } else if (PropagateItemJob* current = createJob(item)) {
            directories.top().second->append(current);
        }
    }

    foreach(PropagatorJob* it, directoriesToRemove) {
        _rootJob->append(it);
    }
JobInMemory* loadJob(Memory* mem, Job* job, int clock){
	if(job->pages==-1){
		fprintf(stderr,"Memory management enabled without setting pages \n"
			"Please check the Job file\n"
			"Aborting...\n");
		exit(EXIT_FAILURE);
	}

	JobInMemory* curjob = findJob(mem->jobs, job);
	if(curjob==NULL){
		curjob = createJob(mem,job,clock);	
	}

	int pages=0;

	if(curjob!=NULL){
		for(int j=0;j<curjob->pages_for_job;j++){
                        Page* thispage = curjob->pages[j];
			if(thispage!=NULL && 
				thispage->job==job &&
				thispage->last_accessed_at != clock) {
				debug_print("Found page: %d for job %s \n", 
					PAGELOC(thispage,mem->pages[0]), job->jobname);
                        	thispage->last_accessed_at = clock; // updates the last accessed time
				pages++;

				list_iterator_Page* it= malloc(sizeof(*it));
			        list_Page_iterator_init(it,mem->LRU_list);
				Page* curpage = NULL;
				while((curpage= list_Page_examine(it))!=NULL){
					if(curpage == thispage){
						list_Page_remove(it);
						
						break;
					}				
					list_Page_next(it);
				}
				list_Page_append(mem->LRU_list, thispage);
				free(it);
			}
			else{
				if(!assignPage(mem,curjob,j,clock)){
					fprintf(stderr,"Unable to assign pages, system error\n");
					exit(EXIT_FAILURE);
				}
			}
			pages++;	
		}
		debug_print("Job:%s has loaded %d pages in memory\n",job->jobname,pages);
	}

	//LRU stuff
	
	return curjob;
}
Ejemplo n.º 10
0
void addJobsFore(pipeline_t* pipeline, int pid){
	int i;

	/* allocates space for the new jobs */
	exeJobs->jobs = (job*)realloc(exeJobs->jobs, (exeJobs->count + pipeline->ncommands)*sizeof(job));
	
	/* Adds all jobs to the list and executes them */
	for (i = 0; i < pipeline->ncommands; i++){
		exeJobs->jobs[exeJobs->count + i] = createJob(pid, pipeline->ground, STOPPED);
		exeJobs->count += 1;	
	}
}
Ejemplo n.º 11
0
/*
Function name: restoreJob
Description: WARNING! Reads from a binary input stream to rsrtore a Job
            structure. The idea is that some higher level
            class (like List or Node) would call this function after having
            checked for the file input stream to be set properly. We
            don't check for EOF or other errors at this level.

    Input: fin ---> binary input stream

    Output:   ---> a pointer to the restored Job structure
    Side Effects: None outside of the Job structure
*/
JobPtr restoreJob(FILE *fin)
{
    int jobid;
    int infoSize;
    JobPtr job;

    fread(&jobid, sizeof(int), 1, fin);
    fread(&infoSize, sizeof(int), 1, fin);
    job = createJob(jobid, "");
    job->info = (char *) malloc(sizeof(char)*infoSize);
    fread(job->info, infoSize, 1, fin);
    return job;
}
Ejemplo n.º 12
0
ServiceJob *Service::startOperationCall(const KConfigGroup &description, QObject *parent)
{
    // TODO: nested groups?
    ServiceJob *job = 0;
    const QString op = description.isValid() ? description.name() : QString();

    RemoteService *rs = qobject_cast<RemoteService *>(this);
    if (!op.isEmpty() && rs && !rs->isReady()) {
        // if we have an operation, but a non-ready remote service, just let it through
        kDebug() << "Remote service is not ready; queueing operation";
        QMap<QString, QVariant> params;
        job = createJob(op, params);
        RemoteServiceJob *rsj = qobject_cast<RemoteServiceJob *>(job);
        if (rsj) {
            rsj->setDelayedDescription(description);
        }
    } else if (!d->config) {
        kDebug() << "No valid operations scheme has been registered";
    } else if (!op.isEmpty() && d->config->hasGroup(op)) {
        if (d->disabledOperations.contains(op)) {
            kDebug() << "Operation" << op << "is disabled";
        } else {
            QMap<QString, QVariant> params = parametersFromDescription(description);
            job = createJob(op, params);
        }
    } else {
        kDebug() << op << "is not a valid group; valid groups are:" << d->config->groupList();
    }

    if (!job) {
        job = new NullServiceJob(destination(), op, this);
    }

    job->setParent(parent ? parent : this);
    connect(job, SIGNAL(finished(KJob*)), this, SLOT(jobFinished(KJob*)));
    QTimer::singleShot(0, job, SLOT(autoStart()));
    return job;
}
Ejemplo n.º 13
0
/**
* Runs tests on the addAtRear function
**/
void addAtRearTest(ListPtr list, int count)
{
	int i;
	for(i = 0; i < count; i++)
	{
		char str[80];
		sprintf(str, "%s: %d", "Job", i);
		JobPtr job = createJob(i, str, i);
		NodePtr node = createNode(job);
		addAtRear(list, node);
	}
	if(DEBUG > 0)
		verifyAddAtRearList(list, count);
}
Ejemplo n.º 14
0
  CDDB::Result Submit::submit( CDInfo cdInfo, const TrackOffsetList& offsetList)
  {
    // If it was an inexact math from the server the discid might
    // be different, so recalculate it
    cdInfo.id = trackOffsetListToId(offsetList);

    makeDiskData( cdInfo, offsetList );

    if (!validCategory(cdInfo.category))
      return InvalidCategory;

    KIO::Job* job = createJob(cdInfo);

    if (!job)
      return UnknownError;

    return runJob(job);
  }
Ejemplo n.º 15
0
/* Adds jobs to the job list and executes them */
void addJobsBack(pipeline_t* pipeline){
	int i, aux;
	int pid, status;

	/* allocates space for the new jobs */
	exeJobs->jobs = (job*)realloc(exeJobs->jobs, (exeJobs->count + pipeline->ncommands)*sizeof(job));

	/* Adds all jobs to the list and executes them */
	for (i = 0; i < pipeline->ncommands; i++){
		/* Redirects the input of stdin for the first process */
		if (REDIRECT_STDIN(pipeline) && i == 0){
			close(0);
			fatal(open(pipeline->file_in, O_RDONLY, S_IRUSR | S_IWUSR) < 0, NULL);
		}

		/* Redirects the output from stdout for the last process */
		if (REDIRECT_STDOUT(pipeline) && i == pipeline->ncommands-1){
			close(1);
			fatal(open(pipeline->file_out, O_CREAT | O_TRUNC | O_RDWR, S_IRUSR | S_IWUSR) < 0, NULL);
		}

		pid = fork(); /* Forks the process */
		fatal(pid<0,NULL);

		if (pid > 0) { /* Parent */
			/* Adds the job to the list */
			exeJobs->jobs[exeJobs->count + i] = createJob(pid, pipeline->ground, RUNNING);
			exeJobs->count += 1;

			/* Waits, if the process is foreground */
			if (RUN_FOREGROUND(pipeline)){
				aux = wait (&status); /* Waits for the child to end */
				fatal (aux<0, NULL);
			}
		} else { /* Child */
			aux = execvp (pipeline->command[i][0], pipeline->command[i]);
			fatal(aux < 0, "Could not find program");
		}		
	}
}
Ejemplo n.º 16
0
int main(int argc, char **argv)
{
    int i;
    int n;
    NodePtr node;
    JobPtr job;
    ListPtr list;
    char *saveFile;

    if (argc < 2) {
        fprintf(stderr, "Usage: %s <list size> [<checkpoint file>] \n",argv[0]);
        exit(1);
    }
    n = atoi(argv[1]);
    saveFile = NULL;
    if (argc == 3) {
        saveFile = argv[2];
    }

    list = createList();
    for (i=0; i<n; i++) {
        job = createJob(i, "cmd args");
        node = createNode(job);
        addAtFront(list, node);
    }

    if (!saveFile) printList(list);
    printList(list);

    if (saveFile) {
        printf("checkpointing to file %s\n", saveFile);
        checkpointList(list, saveFile);
    }

    exit(0);
}
Ejemplo n.º 17
0
void __fastcall TfrmRetrieveMain::btnSaveListClick( TObject *Sender ) {
	String error;
	try {
		LPDbBoxType * boxType = getBoxType( );
		if( boxType == NULL ) {
			return;
		}
		LCDbCryoJob * job = createJob( );
		if( job == NULL ) {
			return;
		}
		Screen->Cursor = crSQLWait;
		createBoxes( *job, *boxType );

	} catch( Exception & ex ) {
		error = ex.Message;
	}
	Screen->Cursor = crDefault;
	if( error.IsEmpty( ) ) {
		ModalResult = mrOk;
	} else {
		Application->MessageBox( error.c_str( ), NULL, MB_OK );
	}
}
Ejemplo n.º 18
0
void OwncloudPropagator::start(const SyncFileItemVector& _syncedItems)
{
    /* This builds all the job needed for the propagation.
     * Each directories is a PropagateDirectory job, which contains the files in it.
     * In order to do that we sort the items by destination. and loop over it. When we enter a
     * directory, we can create the directory job and push it on the stack. */
    SyncFileItemVector items = _syncedItems;
    std::sort(items.begin(), items.end());
    _rootJob.reset(new PropagateDirectory(this));
    QStack<QPair<QString /* directory name */, PropagateDirectory* /* job */> > directories;
    directories.push(qMakePair(QString(), _rootJob.data()));
    QVector<PropagatorJob*> directoriesToRemove;
    QString removedDirectory;
    foreach(const SyncFileItem &item, items) {

        if (!removedDirectory.isEmpty() && item._file.startsWith(removedDirectory)) {
            // this is an item in a directory which is going to be removed.
            if (item._instruction == CSYNC_INSTRUCTION_REMOVE) {
                //already taken care of.  (by the removal of the parent directory)
                continue;
            } else if (item._instruction == CSYNC_INSTRUCTION_NEW && item._isDirectory) {
                // create a new directory within a deleted directory? That can happen if the directory
                // etag were not fetched properly on the previous sync because the sync was aborted
                // while uploading this directory (which is now removed).  We can ignore it.
                continue;
            } else if (item._instruction == CSYNC_INSTRUCTION_IGNORE) {
                continue;
            }

            qWarning() << "WARNING:  Job within a removed directory?  This should not happen!"
                       << item._file << item._instruction;
        }

        while (!item.destination().startsWith(directories.top().first)) {
            directories.pop();
        }

        if (item._isDirectory) {
            PropagateDirectory *dir = new PropagateDirectory(this, item);
            dir->_firstJob.reset(createJob(item));
            if (item._instruction == CSYNC_INSTRUCTION_REMOVE) {
                //We do the removal of directories at the end, because there might be moves from
                // this directories that will happen later.
                directoriesToRemove.append(dir);
                removedDirectory = item._file + "/";

                // We should not update the etag of parent directories of the removed directory
                // since it would be done before the actual remove (issue #1845)
                // NOTE: Currently this means that we don't update those etag at all in this sync,
                //       but it should not be a problem, they will be updated in the next sync.
                for (int i = 0; i < directories.size(); ++i) {
                    directories[i].second->_item._should_update_etag = false;
                }
            } else {
                PropagateDirectory* currentDirJob = directories.top().second;
                currentDirJob->append(dir);
            }
            directories.push(qMakePair(item.destination() + "/" , dir));
        } else if (PropagateItemJob* current = createJob(item)) {
            directories.top().second->append(current);
        }
    }

    foreach(PropagatorJob* it, directoriesToRemove) {
        _rootJob->append(it);
    }
Ejemplo n.º 19
0
void CheckIndexingManager::checkNextCollection()
{
    if (mIndex < mListCollection.count()) {
        createJob();
    }
}
Ejemplo n.º 20
0
int main(int argc, char **argv)
{	
	int i;
	int n;
	int count;
	unsigned int seed=0;

	NodePtr node;
	JobPtr job;
	ListPtr list;

	if (argc < 2) {
		fprintf(stderr, "Usage: %s <list size> [<test size=list size>] [<seed>] \n",argv[0]);
		exit(1);
	}
	n = atoi(argv[1]);
	count = n;
	if (argc >= 3) {
		count = atoi(argv[2]);
	}
	if (argc == 4) {
		seed = atoi(argv[3]);
	}

	list = createList();
	runEdgeCases();
	printf("%s\n%s\n", sep, "Running addAtFrontTest");
	addAtFrontTest(list, count);	
	
	if (DEBUG > 0)
		displayDebugInfo(list);
		
	printf("\n%s\n%s\n", sep, "Running removeFromFrontAll Test");
	removeFrontAll(list, count);

	if (DEBUG > 0)
		displayDebugInfo(list);
	
	printf("\n%s\n%s\n", sep, "Running addAtRear Test");
	addAtRearTest(list, count);
	
	if (DEBUG > 0)
		displayDebugInfo(list);
	
	printf("\n%s\n%s\n", sep, "Running removingFromRear Test");
	removeRearAll(list, count);
	
	if (DEBUG > 0)
		displayDebugInfo(list);
	//for(i = count; i > 0; i--)
		//removeFrontOne(list);
		
	printf("\n%s\n%s\n", sep, "Running removeNode Test");
	addAtRearTest(list, count);
	removeNodeAllTest(list, count);
	
	if (DEBUG > 0)
		displayDebugInfo(list);
	
	printf("\n%s\n%s\n", sep, "Running reverseList Test");
	addAtRearTest(list, count);
	reverseList(list);
	verifyAddAtFrontList(list, count);
	
	if (DEBUG > 0)
		displayDebugInfo(list);
	
	printf("\n%s\n%s\n", sep, "Running random tests");
	for (i=0; i<n; i++)
	{
		job = createJob(i, "args", i);
		node = createNode(job);
		/*printf("job ptr = %p node ptr = %p\n", job, node);*/
		addAtFront(list, node);
	}
	runRandomTests(count, seed, n, list);
	freeList(list);
	exit(0);
}
Ejemplo n.º 21
0
void OwncloudPropagator::start(const SyncFileItemVector& items)
{
    Q_ASSERT(std::is_sorted(items.begin(), items.end()));

    /* Check and log the transmission checksum type */
    ConfigFile cfg;
    const QString checksumType = cfg.transmissionChecksum().toUpper();

    /* if the checksum type is empty, it is not send. No error */
    if( !checksumType.isEmpty() ) {
        if( checksumType == checkSumAdlerUpperC ||
                checksumType == checkSumMD5C    ||
                checksumType == checkSumSHA1C ) {
            qDebug() << "Client sends and expects transmission checksum type" << checksumType;
        } else {
            qWarning() << "Unknown transmission checksum type from config" << checksumType;
        }
    }

    /* This builds all the job needed for the propagation.
     * Each directories is a PropagateDirectory job, which contains the files in it.
     * In order to do that we loop over the items. (which are sorted by destination)
     * When we enter adirectory, we can create the directory job and push it on the stack. */

    _rootJob.reset(new PropagateDirectory(this));
    QStack<QPair<QString /* directory name */, PropagateDirectory* /* job */> > directories;
    directories.push(qMakePair(QString(), _rootJob.data()));
    QVector<PropagatorJob*> directoriesToRemove;
    QString removedDirectory;
    foreach(const SyncFileItemPtr &item, items) {

        if (!removedDirectory.isEmpty() && item->_file.startsWith(removedDirectory)) {
            // this is an item in a directory which is going to be removed.
            PropagateDirectory *delDirJob = dynamic_cast<PropagateDirectory*>(directoriesToRemove.last());

            if (item->_instruction == CSYNC_INSTRUCTION_REMOVE) {
                //already taken care of.  (by the removal of the parent directory)

                // increase the number of subjobs that would be there.
                if( delDirJob ) {
                    delDirJob->increaseAffectedCount();
                }
                continue;
            } else if (item->_instruction == CSYNC_INSTRUCTION_NEW && item->_isDirectory) {
                // create a new directory within a deleted directory? That can happen if the directory
                // etag were not fetched properly on the previous sync because the sync was aborted
                // while uploading this directory (which is now removed).  We can ignore it.
                if( delDirJob ) {
                    delDirJob->increaseAffectedCount();
                }
                continue;
            } else if (item->_instruction == CSYNC_INSTRUCTION_IGNORE) {
                continue;
            }

            qWarning() << "WARNING:  Job within a removed directory?  This should not happen!"
                       << item->_file << item->_instruction;
        }

        while (!item->destination().startsWith(directories.top().first)) {
            directories.pop();
        }

        if (item->_isDirectory) {
            PropagateDirectory *dir = new PropagateDirectory(this, item);
            dir->_firstJob.reset(createJob(item));
            if (item->_instruction == CSYNC_INSTRUCTION_REMOVE) {
                //We do the removal of directories at the end, because there might be moves from
                // this directories that will happen later.
                directoriesToRemove.append(dir);
                removedDirectory = item->_file + "/";

                // We should not update the etag of parent directories of the removed directory
                // since it would be done before the actual remove (issue #1845)
                // NOTE: Currently this means that we don't update those etag at all in this sync,
                //       but it should not be a problem, they will be updated in the next sync.
                for (int i = 0; i < directories.size(); ++i) {
                    directories[i].second->_item->_should_update_metadata = false;
                }
            } else {
                PropagateDirectory* currentDirJob = directories.top().second;
                currentDirJob->append(dir);
            }
            directories.push(qMakePair(item->destination() + "/" , dir));
        } else if (PropagateItemJob* current = createJob(item)) {
            directories.top().second->append(current);
        }
    }

    foreach(PropagatorJob* it, directoriesToRemove) {
        _rootJob->append(it);
    }
Ejemplo n.º 22
0
void runRandomTests(struct parameters *state, ListPtr list)
{
	int i;
	int start;
	int test;
	NodePtr node;
	JobPtr job;
	long int num;

   	srand(state->seed);
	start=0;
	if (state->restart) {
		start = state->done+1;
		srand(state->randomNum);
	}
    for (i=start; i<state->count; i++) {
		num = rand();
        test = num % NUM_TESTS;
		if ((i > 0) && ((i % CHECKPOINT_COUNT) == 0)) {
			fprintf(stderr, "checkpointing list, count = %d\n", i);
			state->done = i-1;
			state->randomNum = num;
			checkpointList(list, state->saveFile);
			checkpointTestSuite(state, stateFile);
		}
        switch (test) {
            case 0:
				if (DEBUG > 1) fprintf(stderr,"addAtFront\n");
                state->n++;
                job = createJob(state->n, "some info");
                node = createNode(job);
                addAtFront(list, node);
                break;
            case 1:
				if (DEBUG > 1) fprintf(stderr,"addAtRear\n");
                state->n++;
                job = createJob(state->n, "some info");
                node = createNode(job);
                addAtRear(list, node);
                break;
            case 2:
				if (DEBUG > 1) fprintf(stderr,"removeFront\n");
                node = removeFront(list);
                break;
            case 3:
				if (DEBUG > 1) fprintf(stderr,"removeRear\n");
                node = removeRear(list);
                break;
            case 4:
				if (DEBUG > 1) fprintf(stderr,"removeNode\n");
                node = removeNode(list, search(list, i));
                break;
            case 5:
				if (DEBUG > 1) fprintf(stderr,"reverseList\n");
                reverseList(list);

            default:
                break;
        }
    }
}
Ejemplo n.º 23
0
/**
* Runs edge tests on the current Doubly Linked List implementation
**/
void runEdgeCases()
{
	ListPtr l = createList();
	NodePtr n = NULL;
	printf("\n%s\n%s", sep, "Running edge cases with NULL values");
	printf("\n%s", "addAtFront");
	addAtFront(NULL, NULL);
	addAtFront(l, NULL);
	addAtFront(NULL, n);
	if(l->size == 0
		&& l->head == NULL
		&& l->tail == NULL)
		printf("\nSuccess");
	else
		printf("\nFail");

	
	printf("\n%s", "addAtRear");
	addAtRear(NULL, NULL);
	addAtRear(l, NULL);
	addAtRear(NULL, n);
	if(l->size == 0
		&& l->head == NULL
		&& l->tail == NULL)
		printf("\nSuccess");
	else
		printf("\nFail");
	
	printf("\n%s", "removeFront");
	n = removeFront(NULL);
	n = removeFront(l);
	if(l->size == 0 
		&& l->head == NULL
		&& l->tail == NULL)
		printf("\nSuccess");
	else
		printf("\nFail");
	
	printf("\n%s", "removeRear");
	n = removeRear(NULL);
	n = removeRear(l);
	if(l->size == 0 
		&& l->head == NULL
		&& l->tail == NULL)
		printf("\nSuccess");
	else
		printf("\nFail");
		
	printf("\n%s", "removeNode");
	n = removeNode(NULL, NULL);
	n = removeNode(l, NULL);
	n = removeNode(NULL, n);
	if(l->size == 0 
		&& n == NULL
		&& l->head == NULL
		&& l->tail == NULL)
		printf("\nSuccess");
	else
		printf("\nFail");
		
	printf("\n%s", "reverseList");
	reverseList(NULL);
	reverseList(l);
	if(l->size == 0
		&& l->head == NULL
		&& l->tail == NULL)
		printf("\nSuccess");
	else
		printf("\nFail");
	
	printf("\n%s", "search");
	int i = 0;
	n = search(NULL, 0);
	n = search(l, 0);
	n = search(NULL, i);
	if(n == NULL)
		printf("\nSuccess");
	else
		printf("\nFail");
		
	printf("\n%s\n%s", sep, "Running edge cases with Single values");
	printf("\n%s", "addAtFront");
	JobPtr job = createJob(1, "Single", 1);
	n = createNode(job);
	l = createList();
	addAtFront(l, n);
	if(l->size == 1 
		&& l->head == n 
		&& l->tail == n 
		&& l->head->next == NULL 
		&& l->head->prev == NULL
		&& l->tail->next == NULL
		&& l->tail->prev == NULL)
		printf("\nSuccess");
	else
		printf("\nFail");
		
	printf("\n%s", "removeFront");
	NodePtr removeFrontNode = removeFront(l);
	if(l->size == 0 
		&& l->head == NULL 
		&& l->tail == NULL 
		&& removeFrontNode == n)
		printf("\nSuccess");
	else
		printf("\nFail");
		
	printf("\n%s", "addAtRear");
	addAtRear(l, n);
	if(l->size == 1 
		&& l->head == n 
		&& l->tail == n 
		&& l->head->next == NULL 
		&& l->head->prev == NULL
		&& l->tail->next == NULL
		&& l->tail->prev == NULL)
		printf("\nSuccess");
	else
		printf("\nFail");
	
	printf("\n%s s", "removeRear");
	NodePtr removeRearNode = removeRear(l);
	if(l->size == 0 
		&& l->head == NULL 
		&& l->tail == NULL 
		&& removeRearNode == n)
		printf("\nSuccess");
	else
		printf("\nFail");
		
	printf("\n%s", "removeNode, empty list");
	NodePtr testnode = removeNode(l, n);
	if(l->size == 0 
		&& l->head == NULL 
		&& l->tail == NULL 
		&& testnode == NULL)
		printf("\nSuccess");
	else
		printf("\nFail");
		
	printf("\n%s", "removeNode, one node, matches");
	addAtFront(l, n);
	testnode = removeNode(l, n);
	if(l->size == 0 
		&& l->head == NULL 
		&& l->tail == NULL 
		&& testnode == n)
		printf("\nSuccess");
	else
		printf("\nFail");
		
	printf("\n%s", "removeNode, one node, no match");
	JobPtr noMatchJob = createJob(1, "no match", 1);
	NodePtr noMatch = createNode(noMatchJob);
	addAtFront(l, noMatch);
	testnode = removeNode(l, n);
	if(l->size == 1 
		&& l->head == noMatch 
		&& l->tail == noMatch 
		&& testnode == NULL
		&& l->head->next == NULL 
		&& l->head->prev == NULL
		&& l->tail->next == NULL
		&& l->tail->prev == NULL)
		printf("\nSuccess");
	else
		printf("\nFail");
	
	printf("\n%s", "reverseList");
	reverseList(l);
	if(l->size == 1 
		&& l->head == noMatch 
		&& l->tail == noMatch 
		&& l->head->next == NULL 
		&& l->head->prev == NULL
		&& l->tail->next == NULL
		&& l->tail->prev == NULL)
		printf("\nSuccess");
	else
		printf("\nFail");
		
	printf("\n%s", "search, matches");
	testnode = search(l, 1);
	if(l->size == 1 
		&& l->head == noMatch 
		&& l->tail == noMatch 
		&& testnode == noMatch
		&& l->head->next == NULL 
		&& l->head->prev == NULL
		&& l->tail->next == NULL
		&& l->tail->prev == NULL)
		printf("\nSuccess");
	else
		printf("\nFail");
		
	printf("\n%s", "search, no match");
	testnode = search(l, 0);
	if(l->size == 1 
		&& l->head == noMatch 
		&& l->tail == noMatch 
		&& testnode == NULL
		&& l->head->next == NULL 
		&& l->head->prev == NULL
		&& l->tail->next == NULL
		&& l->tail->prev == NULL)
		printf("\nSuccess\n");
	else
		printf("\nFail\n");
		
	freeList(l);
}
void BaseCheckoutWizard::slotProgressPageShown()
{
    const QSharedPointer<AbstractCheckoutJob> job = createJob(d->parameterPages, &(d->checkoutPath));
    d->dialog->start(job);
}
Ejemplo n.º 25
0
void OwncloudPropagator::start(const SyncFileItemVector& items)
{
    Q_ASSERT(std::is_sorted(items.begin(), items.end()));

    /* This builds all the jobs needed for the propagation.
     * Each directory is a PropagateDirectory job, which contains the files in it.
     * In order to do that we loop over the items. (which are sorted by destination)
     * When we enter a directory, we can create the directory job and push it on the stack. */

    _rootJob.reset(new PropagateDirectory(this));
    QStack<QPair<QString /* directory name */, PropagateDirectory* /* job */> > directories;
    directories.push(qMakePair(QString(), _rootJob.data()));
    QVector<PropagatorJob*> directoriesToRemove;
    QString removedDirectory;
    foreach(const SyncFileItemPtr &item, items) {

        if (!removedDirectory.isEmpty() && item->_file.startsWith(removedDirectory)) {
            // this is an item in a directory which is going to be removed.
            PropagateDirectory *delDirJob = dynamic_cast<PropagateDirectory*>(directoriesToRemove.first());

            if (item->_instruction == CSYNC_INSTRUCTION_REMOVE) {
                // already taken care of. (by the removal of the parent directory)

                // increase the number of subjobs that would be there.
                if( delDirJob ) {
                    delDirJob->increaseAffectedCount();
                }
                continue;
            } else if (item->_isDirectory
                       && (item->_instruction == CSYNC_INSTRUCTION_NEW
                           || item->_instruction == CSYNC_INSTRUCTION_TYPE_CHANGE)) {
                // create a new directory within a deleted directory? That can happen if the directory
                // etag was not fetched properly on the previous sync because the sync was aborted
                // while uploading this directory (which is now removed).  We can ignore it.
                if( delDirJob ) {
                    delDirJob->increaseAffectedCount();
                }
                continue;
            } else if (item->_instruction == CSYNC_INSTRUCTION_IGNORE) {
                continue;
            } else if (item->_instruction == CSYNC_INSTRUCTION_RENAME) {
                // all is good, the rename will be executed before the directory deletion
            } else {
                qWarning() << "WARNING:  Job within a removed directory?  This should not happen!"
                           << item->_file << item->_instruction;
            }
        }

        while (!item->destination().startsWith(directories.top().first)) {
            directories.pop();
        }

        if (item->_isDirectory) {
            PropagateDirectory *dir = new PropagateDirectory(this, item);
            dir->_firstJob.reset(createJob(item));

            if (item->_instruction == CSYNC_INSTRUCTION_TYPE_CHANGE
                    && item->_direction == SyncFileItem::Up) {
                // Skip all potential uploads to the new folder.
                // Processing them now leads to problems with permissions:
                // checkForPermissions() has already run and used the permissions
                // of the file we're about to delete to decide whether uploading
                // to the new dir is ok...
                foreach(const SyncFileItemPtr &item2, items) {
                    if (item2->destination().startsWith(item->destination() + "/")) {
                        item2->_instruction = CSYNC_INSTRUCTION_NONE;
                        _anotherSyncNeeded = true;
                    }
                }
            }

            if (item->_instruction == CSYNC_INSTRUCTION_REMOVE) {
                // We do the removal of directories at the end, because there might be moves from
                // these directories that will happen later.
                directoriesToRemove.prepend(dir);
                removedDirectory = item->_file + "/";

                // We should not update the etag of parent directories of the removed directory
                // since it would be done before the actual remove (issue #1845)
                // NOTE: Currently this means that we don't update those etag at all in this sync,
                //       but it should not be a problem, they will be updated in the next sync.
                for (int i = 0; i < directories.size(); ++i) {
                    if (directories[i].second->_item->_instruction == CSYNC_INSTRUCTION_UPDATE_METADATA)
                        directories[i].second->_item->_instruction = CSYNC_INSTRUCTION_NONE;
                }
            } else {
                PropagateDirectory* currentDirJob = directories.top().second;
                currentDirJob->append(dir);
            }
            directories.push(qMakePair(item->destination() + "/" , dir));
        } else if (PropagateItemJob* current = createJob(item)) {
Ejemplo n.º 26
0
    int h = d->imageLabel->contentsRect().height() - 4;

    if (d->m_job) {
        disconnect(d->m_job, SIGNAL(result(KJob *)),
                    this, SLOT( _k_slotResult( KJob * )));
        disconnect(d->m_job, SIGNAL(gotPreview(const KFileItem&,
                                                const QPixmap& )), this,
                SLOT( gotPreview( const KFileItem&, const QPixmap& ) ));

        disconnect(d->m_job, SIGNAL(failed(const KFileItem&)),
                    this, SLOT(_k_slotFailed(const KFileItem&)));

        d->m_job->kill();
    }

    d->m_job = createJob(url, w, h);
    if ( force ) // explicitly requested previews shall always be generated!
        d->m_job->setIgnoreMaximumSize(true);

    connect(d->m_job, SIGNAL(result(KJob *)),
                this, SLOT( _k_slotResult( KJob * )));
    connect(d->m_job, SIGNAL(gotPreview(const KFileItem&,
                                        const QPixmap& )),
                SLOT( gotPreview( const KFileItem&, const QPixmap& ) ));

    connect(d->m_job, SIGNAL(failed(const KFileItem&)),
                this, SLOT(_k_slotFailed(const KFileItem&)));
}

void KImageFilePreview::resizeEvent( QResizeEvent * )
{
int main() {
    struct timeval tpstart,tpend;
    float allocateTime = 0;
    float activeTime = 0;
    float releaseTime = 0;
    float timeuse;
    char *rmHost = "localhost";
    char *rmPort = "8032";
    char *schedHost = "localhost";
    char *schedPort = "8030";
    char *amHost = "localhost";
    int32_t amPort = 10;
    char *am_tracking_url = "url";
    int heartbeatInterval = 1000;

    //0. new client
    LibYarnClient_t *client = NULL;
    int result = newLibYarnClient(rmHost, rmPort, schedHost, schedPort,
                                  amHost, amPort, am_tracking_url,&client,heartbeatInterval);

    //1. createJob
    char *jobName = "libyarn";
    char *queue = "default";
    char *jobId = NULL;
    result = createJob(client, jobName, queue,&jobId);
    if (result != FUNCTION_SUCCEEDED) {
        const char* errorMessage = getErrorMessage();
        printf("1. createJob, errorMessage:%s\n",errorMessage);
    }

    int i,j;
    for (j = 0; j < 10; j++) {
        LibYarnResourceRequest_t resRequest;
        resRequest.priority = 1;
        resRequest.host = "*";
        resRequest.vCores = 1;
        resRequest.memory = 1024;
        resRequest.num_containers = 2;
        resRequest.relax_locality = 1;

        char *blackListAdditions[0];
        char *blackListRemovals[0];

        //1. allocate resource
        LibYarnResource_t *allocatedResourcesArray;
        int allocatedResourceArraySize;
        gettimeofday(&tpstart,NULL);
        result = allocateResources(client, jobId, &resRequest, blackListAdditions,
                                   0, blackListRemovals, 0, &allocatedResourcesArray, &allocatedResourceArraySize,5);
        gettimeofday(&tpend,NULL);
        timeuse=1000000*(tpend.tv_sec-tpstart.tv_sec)+tpend.tv_usec-tpstart.tv_usec;
        allocateTime += timeuse;

        if (result != FUNCTION_SUCCEEDED) {
            const char* errorMessage = getErrorMessage();
            printf("2. allocateResources, errorMessage:%s\n",errorMessage);
        }

        int32_t activeContainerIds[allocatedResourceArraySize];
        int32_t releaseContainerIds[allocatedResourceArraySize];
        int32_t statusContainerIds[allocatedResourceArraySize];
        for (i = 0 ; i < allocatedResourceArraySize; i++) {
            activeContainerIds[i] = allocatedResourcesArray[i].containerId;
            releaseContainerIds[i] = allocatedResourcesArray[i].containerId;
            statusContainerIds[i] = allocatedResourcesArray[i].containerId;
        }

        //3. active
        gettimeofday(&tpstart,NULL);
        result = activeResources(client, jobId, activeContainerIds,allocatedResourceArraySize);
        gettimeofday(&tpend,NULL);
        timeuse=1000000*(tpend.tv_sec-tpstart.tv_sec)+tpend.tv_usec-tpstart.tv_usec;
        activeTime += timeuse;
        if (result != FUNCTION_SUCCEEDED) {
            const char* errorMessage = getErrorMessage();
            printf("2. activeResources, errorMessage:%s\n",errorMessage);
        }

        int *activeFailIds;
        int activeFailSize;
        result = getActiveFailContainerIds(client,&activeFailIds,&activeFailSize);
        for (i = 0; i < activeFailSize; i++) {
            printf("Active Fail Container Id:%d\n",activeFailIds[i]);
        }
        //sleep(160);

        //4. getContainerReport
        LibYarnContainerReport_t *containerReportArray;
        int containerReportArraySize;
        result = getContainerReports(client, jobId, &containerReportArray,
                                     &containerReportArraySize);
        if (result != FUNCTION_SUCCEEDED) {
            const char* errorMessage = getErrorMessage();
            printf(" The getContainerReports, errorMessage:%s\n", errorMessage);
        }

        freeContainerReportArray(containerReportArray, containerReportArraySize);

        //4. getContainerReport
        LibYarnContainerStatus_t *containerStatusArray;
        int containerStatusArraySize;
        result = getContainerStatuses(client, jobId, statusContainerIds,
                                      allocatedResourceArraySize, &containerStatusArray,
                                      &containerStatusArraySize);
        if (result != FUNCTION_SUCCEEDED) {
            const char* errorMessage = getErrorMessage();
            printf(" The getContainerStatus, errorMessage:%s\n", errorMessage);
        }
        freeContainerStatusArray(containerStatusArray,containerStatusArraySize);

        //5. release
        gettimeofday(&tpstart,NULL);
        result = releaseResources(client, jobId, releaseContainerIds,allocatedResourceArraySize);
        gettimeofday(&tpend,NULL);
        timeuse=1000000*(tpend.tv_sec-tpstart.tv_sec)+tpend.tv_usec-tpstart.tv_usec;
        releaseTime += timeuse;

        result = getActiveFailContainerIds(client,&activeFailIds,&activeFailSize);
        for (i = 0; i < activeFailSize; i++) {
            printf("Active Fail Container Id:%d\n",activeFailIds[i]);
        }
        free(activeFailIds);
        freeMemAllocatedResourcesArray(allocatedResourcesArray, allocatedResourceArraySize);

        //6. getQueueInfo
        LibYarnQueueInfo_t *queueInfo = NULL;
        result = getQueueInfo(client, queue, true, true, true, &queueInfo);
        if (result != FUNCTION_SUCCEEDED) {
            const char* errorMessage = getErrorMessage();
            printf(" The getQueueInfo, errorMessage:%s\n",errorMessage);
        }

        freeMemQueueInfo(queueInfo);

        //7. getCluster
        LibYarnNodeReport_t *nodeReportArray;
        int nodeReportArraySize;
        result = getClusterNodes(client, NODE_STATE_RUNNING, &nodeReportArray, &nodeReportArraySize);
        if (result != FUNCTION_SUCCEEDED) {
            const char* errorMessage = getErrorMessage();
            printf(" The getClusterNodes, errorMessage:%s\n",errorMessage);
        }

        freeMemNodeReportArray(nodeReportArray, nodeReportArraySize);

        //8. getApplicationReport
        LibYarnApplicationReport_t *applicationReport = NULL;
        result = getApplicationReport(client, jobId, &applicationReport);
        if (result != FUNCTION_SUCCEEDED) {
            const char* errorMessage = getErrorMessage();
            printf(" The getApplicationReport, errorMessage:%s\n",
                   errorMessage);
        }

        freeApplicationReport(applicationReport);
    }
    printf("allocateTime:%f s\n",allocateTime/1000000);
    printf("activeTime:%f s\n",activeTime/1000000);
    printf("releaseTime:%f s\n",releaseTime/1000000);
    //9. finish
    result = finishJob(client, jobId, APPLICATION_SUCCEEDED);
    if (result != FUNCTION_SUCCEEDED) {
        const char* errorMessage = getErrorMessage();
        printf(" The finishJob, errorMessage:%s\n", errorMessage);
    }
    free(jobId);
    //10. free client
    deleteLibYarnClient(client);

    return 0;
}
Ejemplo n.º 28
0
int main() {
    char *rmHost = "master";
    char *rmPort = "8032";
    char *schedHost = "master";
    char *schedPort = "8030";
    char *amHost = "master";
    int32_t amPort = 8090;
    char *am_tracking_url = "url";
    int heartbeatInterval = 1000000;
    int i=0;

    //0. new client
    LibYarnClient_t *client = NULL;
    int result = newLibYarnClient("postgres", rmHost, rmPort, schedHost, schedPort,
                                  amHost, amPort, am_tracking_url,&client,heartbeatInterval);
    printf("newLibYarnClient Result Code:%d\n",result);

    //1. createJob
    char *jobName = "libyarn";
    char *queue = "default";
    char *jobId = NULL;
    result = createJob(client, jobName, queue,&jobId);
    printf("1. createJob, jobid:%s The createJob Result Code:%d\n", jobId,result);
    if (result != FUNCTION_SUCCEEDED) {
        const char* errorMessage = getErrorMessage();
        printf("1. createJob, errorMessage:%s\n",errorMessage);
    }


    char *blackListAdditions[0];
    char *blackListRemovals[0];

    //1. allocate resource
    LibYarnResource_t *allocatedResourcesArray;
    int allocatedResourceArraySize;
    result = allocateResources(client, jobId, 1, 1, 1024, 5,
                               blackListAdditions, 0, blackListRemovals, 0, NULL, 0,
                               &allocatedResourcesArray, &allocatedResourceArraySize);
    printf("The allocateResources Result Code:%d\n",result);
    if (result != FUNCTION_SUCCEEDED) {
        const char* errorMessage = getErrorMessage();
        printf("2. allocateResources, errorMessage:%s\n",errorMessage);
    }

    int64_t activeContainerIds[allocatedResourceArraySize];
    int64_t releaseContainerIds[allocatedResourceArraySize];
    int64_t statusContainerIds[allocatedResourceArraySize];
    printf("2. allocateResources, allocatedResourceArraySize:%d\n", allocatedResourceArraySize);
    for (i = 0 ; i < allocatedResourceArraySize; i++) {
        puts("----------------------------");
        printf("allocatedResourcesArray[i].containerId:%ld\n", allocatedResourcesArray[i].containerId);
        activeContainerIds[i] = allocatedResourcesArray[i].containerId;
        releaseContainerIds[i] = allocatedResourcesArray[i].containerId;
        statusContainerIds[i] = allocatedResourcesArray[i].containerId;
        printf("allocatedResourcesArray[i].host:%s\n", allocatedResourcesArray[i].host);
        printf("allocatedResourcesArray[i].port:%d\n", allocatedResourcesArray[i].port);
        printf("allocatedResourcesArray[i].nodeHttpAddress:%s\n", allocatedResourcesArray[i].nodeHttpAddress);
        printf("allocatedResourcesArray[i].vCores:%d\n", allocatedResourcesArray[i].vCores);
        printf("allocatedResourcesArray[i].memory:%d\n", allocatedResourcesArray[i].memory);
    }

    //3. active
    result = activeResources(client, jobId, activeContainerIds,allocatedResourceArraySize);
    printf("The activeResources  Result Code:%d\n",result);
    if (result != FUNCTION_SUCCEEDED) {
        const char* errorMessage = getErrorMessage();
        printf("2. activeResources, errorMessage:%s\n",errorMessage);
    }

    sleep(10);

    int64_t *activeFailIds;
    int activeFailSize;
    result = getActiveFailContainerIds(client,&activeFailIds,&activeFailSize);
    printf("Active Fail Container Size:%d\n",activeFailSize);
    for (i = 0; i < activeFailSize; i++) {
        printf("Active Fail Container Id:%ld\n",activeFailIds[i]);
    }

    //4. getContainerReport
    LibYarnContainerReport_t *containerReportArray;
    int containerReportArraySize;
    result = getContainerReports(client, jobId, &containerReportArray,
                                 &containerReportArraySize);
    printf("The getContainerReports Result Code:%d\n", result);
    if (result != FUNCTION_SUCCEEDED) {
        const char* errorMessage = getErrorMessage();
        printf(" The getContainerReports, errorMessage:%s\n", errorMessage);
    }

    printf("containerReportArraySize=%d\n", containerReportArraySize);
    for (i = 0; i < containerReportArraySize; i++) {
        printf("-------------container: %d--------------------------\n", i);
        printf("containerId:%ld\n", containerReportArray[i].containerId);
        printf("vCores:%d\n", containerReportArray[i].vCores);
        printf("memory:%d\n", containerReportArray[i].memory);
        printf("host:%s\n", containerReportArray[i].host);
        printf("port:%d\n", containerReportArray[i].port);
        printf("exitStatus:%d\n", containerReportArray[i].exitStatus);
        printf("state:%d\n", containerReportArray[i].state);
    }
    freeContainerReportArray(containerReportArray, containerReportArraySize);

    //4. getContainerReport
    LibYarnContainerStatus_t *containerStatusArray;
    int containerStatusArraySize;
    result = getContainerStatuses(client, jobId, statusContainerIds,
                                  allocatedResourceArraySize, &containerStatusArray,
                                  &containerStatusArraySize);
    printf("The getContainerStatus Result Code:%d\n", result);
    if (result != FUNCTION_SUCCEEDED) {
        const char* errorMessage = getErrorMessage();
        printf(" The getContainerStatus, errorMessage:%s\n", errorMessage);
    }

    printf("containerStatusArraySize=%d\n", containerStatusArraySize);
    for (i = 0; i < containerStatusArraySize; i++) {
        printf("-------------container: %d--------------------------\n", i);
        printf("containerId:%ld\n", containerStatusArray[i].containerId);
        printf("exitStatus:%d\n", containerStatusArray[i].exitStatus);
        printf("state:%d\n", containerStatusArray[i].state);
        printf("diagnostics:%s\n", containerStatusArray[i].diagnostics);
    }
    freeContainerStatusArray(containerStatusArray,containerStatusArraySize);

    //6. getQueueInfo
    LibYarnQueueInfo_t *queueInfo = NULL;
    result = getQueueInfo(client, queue, true, true, true, &queueInfo);
    printf("The getQueueInfo  Result Code:%d\n",result);
    if (result != FUNCTION_SUCCEEDED) {
        const char* errorMessage = getErrorMessage();
        printf(" The getQueueInfo, errorMessage:%s\n",errorMessage);
    }

    printf("QueueInfo: queueInfo->queueName:%s, queueInfo->capacity:%f, queueInfo->maximumCapacity:%f, queueInfo->currentCapacity:%f, queueInfo->state:%d\n",
           queueInfo->queueName, queueInfo->capacity, queueInfo->maximumCapacity,
           queueInfo->currentCapacity, queueInfo->state);
    puts("---------chilldQueue:");
    for (i = 0; i < queueInfo->childQueueNameArraySize; i++) {
        printf("QueueInfo: queueInfo->childQueueNameArray[%d]:%s\n", i, queueInfo->childQueueNameArray[i]);
    }
    freeMemQueueInfo(queueInfo);

    //7. getCluster
    LibYarnNodeReport_t *nodeReportArray;
    int nodeReportArraySize;
    result = getClusterNodes(client, NODE_STATE_RUNNING, &nodeReportArray, &nodeReportArraySize);
    printf("The getClusterNodes Result Code:%d\n",result);
    if (result != FUNCTION_SUCCEEDED) {
        const char* errorMessage = getErrorMessage();
        printf(" The getClusterNodes, errorMessage:%s\n",errorMessage);
    }

    printf("nodeReportArraySize=%d\n", nodeReportArraySize);
    for (i = 0; i < nodeReportArraySize; i++) {
        printf("-------------node %d--------------------------\n", i);
        printf("host:%s\n", nodeReportArray[i].host);
        printf("port:%d\n", nodeReportArray[i].port);
        printf("httpAddress:%s\n", nodeReportArray[i].httpAddress);
        printf("rackName:%s\n", nodeReportArray[i].rackName);
        printf("memoryUsed:%d\n", nodeReportArray[i].memoryUsed);
        printf("vcoresUsed:%d\n", nodeReportArray[i].vcoresUsed);
        printf("memoryCapability:%d\n", nodeReportArray[i].memoryCapability);
        printf("vcoresCapability:%d\n", nodeReportArray[i].vcoresCapability);
        printf("numContainers:%d\n", nodeReportArray[i].numContainers);
        printf("nodeState:%d\n", nodeReportArray[i].nodeState);
        printf("healthReport:%s\n", nodeReportArray[i].healthReport);
        printf("lastHealthReportTime:%lld\n", nodeReportArray[i].lastHealthReportTime);
    }
    freeMemNodeReportArray(nodeReportArray, nodeReportArraySize);

    //8. getApplicationReport
    LibYarnApplicationReport_t *applicationReport = NULL;
    result = getApplicationReport(client, jobId, &applicationReport);
    printf("The getApplicationReport  Result Code:%d\n", result);
    if (result != FUNCTION_SUCCEEDED) {
        const char* errorMessage = getErrorMessage();
        printf(" The getApplicationReport, errorMessage:%s\n",
               errorMessage);
    }
    printf("-------------ApplicationReport-------------------------\n");
    printf("appId:%d\n", applicationReport->appId);
    printf("user:%s\n",  applicationReport->user);
    printf("queue:%s\n", applicationReport->queue);
    printf("name:%s\n", applicationReport->name);
    printf("host:%s\n", applicationReport->host);
    printf("port:%d\n", applicationReport->port);
    printf("status:%d\n", applicationReport->status);

    freeApplicationReport(applicationReport);

    //5. release
    result = releaseResources(client, jobId, releaseContainerIds,allocatedResourceArraySize);
    printf("The releaseResources  Result Code:%d\n",result);

    result = getActiveFailContainerIds(client,&activeFailIds,&activeFailSize);
    printf("Active Fail Container Size:%d\n",activeFailSize);
    for (i = 0; i < activeFailSize; i++) {
        printf("Active Fail Container Id:%d\n",activeFailIds[i]);
    }
    free(activeFailIds);
    freeMemAllocatedResourcesArray(allocatedResourcesArray, allocatedResourceArraySize);
    printf("freeMemAllocated is OK\n");

    //9. finish
    printf("jobId:%s\n", jobId);
    result = finishJob(client, jobId, APPLICATION_SUCCEEDED);
    printf("The finishJob Result Code:%d\n", result);
    if (result != FUNCTION_SUCCEEDED) {
        const char* errorMessage = getErrorMessage();
        printf(" The finishJob, errorMessage:%s\n", errorMessage);
    }
    free(jobId);
    //10. free client
    deleteLibYarnClient(client);

    return 0;
}
Ejemplo n.º 29
0
void SftpChannelPrivate::handleMkdirStatus(const JobMap::Iterator &it,
    const SftpStatusResponse &response)
{
    SftpMakeDir::Ptr op = it.value().staticCast<SftpMakeDir>();
    if (op->parentJob == SftpUploadDir::Ptr()) {
        handleStatusGeneric(it, response);
        return;
    }
    if (op->parentJob->hasError) {
        m_jobs.erase(it);
        return;
    }

    typedef QMap<SftpMakeDir::Ptr, SftpUploadDir::Dir>::Iterator DirIt;
    DirIt dirIt = op->parentJob->mkdirsInProgress.find(op);
    Q_ASSERT(dirIt != op->parentJob->mkdirsInProgress.end());
    const QString &remoteDir = dirIt.value().remoteDir;
    if (response.status == SSH_FX_OK) {
        emit dataAvailable(op->parentJob->jobId,
            tr("Created remote directory '%1'.").arg(remoteDir));
    } else if (response.status == SSH_FX_FAILURE) {
        emit dataAvailable(op->parentJob->jobId,
            tr("Remote directory '%1' already exists.").arg(remoteDir));
    } else {
        op->parentJob->setError();
        emit finished(op->parentJob->jobId,
            tr("Error creating directory '%1': %2")
            .arg(remoteDir, response.errorString));
        m_jobs.erase(it);
        return;
    }

    QDir localDir(dirIt.value().localDir);
    const QFileInfoList &dirInfos
        = localDir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot);
    foreach (const QFileInfo &dirInfo, dirInfos) {
        const QString remoteSubDir = remoteDir + QLatin1Char('/') + dirInfo.fileName();
        const SftpMakeDir::Ptr mkdirOp(
            new SftpMakeDir(++m_nextJobId, remoteSubDir, op->parentJob));
        op->parentJob->mkdirsInProgress.insert(mkdirOp,
            SftpUploadDir::Dir(dirInfo.absoluteFilePath(), remoteSubDir));
        createJob(mkdirOp);
    }

    const QFileInfoList &fileInfos = localDir.entryInfoList(QDir::Files);
    foreach (const QFileInfo &fileInfo, fileInfos) {
        QSharedPointer<QFile> localFile(new QFile(fileInfo.absoluteFilePath()));
        if (!localFile->open(QIODevice::ReadOnly)) {
            op->parentJob->setError();
            emit finished(op->parentJob->jobId,
                tr("Could not open local file '%1': %2")
                .arg(fileInfo.absoluteFilePath(), localFile->errorString()));
            m_jobs.erase(it);
            return;
        }

        const QString remoteFilePath = remoteDir + QLatin1Char('/') + fileInfo.fileName();
        SftpUploadFile::Ptr uploadFileOp(new SftpUploadFile(++m_nextJobId,
            remoteFilePath, localFile, SftpOverwriteExisting, op->parentJob));
        createJob(uploadFileOp);
        op->parentJob->uploadsInProgress.append(uploadFileOp);
    }
Ejemplo n.º 30
0
void runFJob() {
  int  w, h[NJOBS], n;
  float x1, y1[NJOBS], x2, y2[NJOBS];

  float diff = ((1.0*jobHeight) / HEIGHT) * 0.01;
  x1 = 0.40; //left

  y1[0] = 0.20; //up
  for (int i = 1; i < NJOBS; i++)
    y1[i] = y1[i-1]+diff;//0.20828125;


  x2 = 0.41; //right


  y2[0] = 0.20 + diff;//down
  for (int i = 1; i < NJOBS; i++)
    y2[i] = y2[i-1]+diff;



  w  = WIDTH;  //  -
  for (int i = 0; i < NJOBS; i++)
    h[i] = jobHeight;//-   +




  n  = MAXITER;//  +


  init_rgb();

  printf ("x1=%f y1=%f x2=%f y2=%f w=%d h=%d n=%d file=%s\n",
      x1, y1[0], x2, y2[1], w, h[0], n, "file.ppm");



  nGlobItems[0] = 512;
  nGlobItems[1] = jobHeight < 512 ? jobHeight : 512;
  int nGlobItemsProfile[2] = {512,512};
  nItemsGroup[0] = 8;
  nItemsGroup[1] = (jobHeight % 8) == 0 ? 8 : (jobHeight % 4 == 0) ? 4 : (jobHeight % 2 == 0) ? 2 : 1;
  int nItemsGroupGPU[2];
  nItemsGroupGPU[0] = nItemsGroupGPU[1] = groupSize;

  //jobs for initial profiling
/*  float y1Prof=0.20,  y2Prof=0.21;
  int   wProf =1024,  hProf =1024,  nProf = 1048576;

  for (int i = 0; i < nPUs ; i++) {
    Job *job = createJob();
    setJobID(job, -1-i);
    setAllowPU(job, CL_DEVICE_TYPE_CPU);
    if (GPUs)
      setAllowPU(job, CL_DEVICE_TYPE_GPU);
    setJobCategory(job, 1);
    loadSourceFile(job, "mandel.cl");
    setStartingKernel(job, "calc_tile");

    setArgument(job, INPUT,  1 * sizeof(float), &x1);
    setArgument(job, INPUT,  1 * sizeof(float), &y2Prof);
    setArgument(job, INPUT,  1 * sizeof(float), &x2);
    setArgument(job, INPUT,  1 * sizeof(float), &y1Prof);
    setArgument(job, INPUT,  1 * sizeof(int), &wProf);
    setArgument(job, INPUT,  1 * sizeof(int), &hProf);
    setArgument(job, INPUT,  1 * sizeof(int), &nProf);
    setArgument(job, OUTPUT, wProf*hProf * sizeof(int), NULL);

    setDimensions(job, 2, nGlobItemsProfile, nItemsGroup);
    setResultCollector(job, defaultRCID);
    requestResultNotification(job);

    if (i == 0) {
      sleep(50);
//      printf("Type something to send the first PROFILING job.\n");
//      char asd[100];
//      scanf("%s",asd);
    }
    sendJobToExec(job, defaultSchedID);
  }

  printf("JM  (%i): Sent all PROFILING jobs.\n", myid);
  //jobs for actual work
*/sleep(50);
  for (int i = 0; i < NJOBS; i++) {

    job[i] = createJob();


    setJobID(job[i], i);

    setAllowPU(job[i], CL_DEVICE_TYPE_CPU);
    if (GPUs)
      setAllowPU(job[i], CL_DEVICE_TYPE_GPU);

    setJobCategory(job[i], 1);
    loadSourceFile(job[i], "mandel.cl");
    setStartingKernel(job[i], "calc_tile");


    setArgument(job[i], INPUT,  1 * sizeof(float), &x1);
    setArgument(job[i], INPUT,  1 * sizeof(float), &(y2[(NJOBS-1)-i]));
    setArgument(job[i], INPUT,  1 * sizeof(float), &x2);
    setArgument(job[i], INPUT,  1 * sizeof(float), &(y1[(NJOBS-1)-i]));
    setArgument(job[i], INPUT,  1 * sizeof(int), &w);
    setArgument(job[i], INPUT,  1 * sizeof(int), &(h[i]));
    setArgument(job[i], INPUT,  1 * sizeof(int), &n);
    setArgument(job[i], OUTPUT, w*(h[i]) * sizeof(int), NULL);

    setDimensions(job[i], 2, nGlobItems, nItemsGroup);
    setResultCollector(job[i], defaultRCID);
    requestResultNotification(job[i]);
  }

  pthread_mutex_lock(&end_mutex);
//  while(profilesReceived != nPUs)
//    pthread_cond_wait(&profile_over, &end_mutex);
  pthread_mutex_unlock(&end_mutex);
  //char asd[100];
  sleep(7);
  printf("\n\n\n#####PROFILING OVER#####\n");// Type something to send the first (real) job.\n");
  //      scanf("%s",asd);
  sleep(2);
  if (gettimeofday(&start, NULL)) {
    perror("gettimeofday");
    exit (EXIT_FAILURE);
  }

//  printf("JM: Sending now!\n");
  for (int i = 0; i < NJOBS; i++)
    sendJobToExec(job[i], defaultSchedID);


}