Пример #1
0
string Process::run_job(string run_file, string metric) {
	/*char qsub[] = "/usr/local/sge/bin/linux-x64/qsub ";
    strcat(qsub, run_file);
    strcat(qsub, " ");
    strcat(qsub, metric);*/

    //string qsub = "/usr/local/sge/bin/linux-x64/qsub -q \\!gpu " + run_file + " " + metric;
    string qsub = "qsub -q \\!gpu " + run_file + " " + metric;
    string qsub_r = exec(qsub.c_str());

    return getJobID(qsub_r);
}
Пример #2
0
///////////////////////////////////////////////////////////////////////////////////////////
//
// CS     : PUBLIC gint checkPrinterAndJobState(gchar *pDestName, gboolean *pPrinterReady, gboolean *pJobExist)
// IN     : gchar *pDestName : Printer name.
// OUT    : gboolean *pPrinterReady : Any printers registered into CUPS or not.
//          gboolean *pJobExist : Active job exists or not.
// RETURN : ID_ERR_NO_ERROR : No error.
//          ID_ERR_CUPS_API_FAILED : Error occured in CUPS API.
//
PUBLIC gint checkPrinterAndJobState(gchar *pDestName, gboolean *pPrinterReady, gboolean *pJobExist)
{
/*** Parameters start ***/
	gchar	printerURI[HTTP_MAX_URI];	// Printer URI.
	gchar	serverName[HTTP_MAX_URI];	// CUPS server name.
	gint	retVal = ID_ERR_NO_ERROR;	// Return value.
/*** Parameters end ***/

	snprintf(printerURI, sizeof(printerURI), "ipp://localhost/printers/%s", pDestName);
	strncpy(serverName, "localhost", HTTP_MAX_URI-1);

	// Check printer state.
	retVal = checkPrinterState(pDestName, printerURI, serverName);
	if (retVal == ID_ERR_NO_ERROR) {
		if (pPrinterReady != NULL) {
			*pPrinterReady = TRUE;
		}
	}
	else {
		if (pPrinterReady != NULL) {
			*pPrinterReady = FALSE;
		}
	}

	if (retVal == ID_ERR_NO_ERROR && pJobExist != NULL) {
		// Check active job exist.
		retVal = getJobID(pDestName, printerURI, serverName, NULL);
		if (retVal == ID_ERR_NO_ERROR) {
			*pJobExist = TRUE;
		}
		else {
			*pJobExist = FALSE;
		}
	}

	if (retVal == ID_ERR_UNKNOWN_PRINTER || retVal == ID_ERR_PRINT_JOB_NOT_EXIST) {
		retVal = ID_ERR_NO_ERROR;
	}

	return(retVal);
}// End getPrinterAndJobState
Пример #3
0
OnlineAstrometryParser::OnlineAstrometryParser() : AstrometryParser()
{
    job_retries=0;
    solver_retries=0;

    networkManager = new QNetworkAccessManager(this);

    connect(this, SIGNAL(authenticateFinished()), this, SLOT(uploadFile()));
    connect(this, SIGNAL(uploadFinished()), this, SLOT(getJobID()));
    connect(this, SIGNAL(jobIDFinished()), this, SLOT(checkJobs()));
    connect(this, SIGNAL(jobFinished()), this, SLOT(checkJobCalibration()));

    // Reset parity on solver failure
    connect(this, &OnlineAstrometryParser::solverFailed, this, [&]() { parity = -1;});

    connect(this, SIGNAL(solverFailed()), this, SLOT(resetSolver()));
    connect(this, SIGNAL(solverFinished(double,double,double, double)), this, SLOT(resetSolver()));

    downsample_factor = 0;
    isGenerated = true;

}
Пример #4
0
///////////////////////////////////////////////////////////////////////////////////////////
//
// CS     : PUBLIC gint removeJob(gchar *pDestName)
// IN     : gchar *pDestName : Printer name.
// OUT    : None.
// RETURN : ID_ERR_NO_ERROR : No error.
//          ID_ERR_CUPS_API_FAILED : Error occured in CUPS API.
//
PUBLIC gint removeJob(gchar *pDestName)
{
/*** Parameters start ***/
	http_t			*pHTTP;						// Pointer to HTTP connection.
	ipp_t			*pRequest,					// Pointer to CUPS IPP request.
					*pResponse;					// Pointer to CUPS IPP response.
	cups_lang_t		*pLanguage;					// Pointer to language.
	gchar			printerURI[HTTP_MAX_URI];	// Printer URI.
	gchar			serverName[HTTP_MAX_URI];	// CUPS server name.
	gint			jobID = 0;					// Job ID.
	gint			retVal = ID_ERR_NO_ERROR;	// Return value.
/*** Parameters end ***/

	// Initialize buffer.
	memset(printerURI, 0, sizeof(printerURI));
	memset(serverName, 0, sizeof(serverName));

	// Get printer URI and CUPS server name.
	retVal = getPrinterURI(pDestName, printerURI, serverName, HTTP_MAX_URI);
	if (retVal == ID_ERR_NO_ERROR) {
		retVal = getJobID(pDestName, printerURI, serverName, &jobID);
		if (retVal == ID_ERR_PRINT_JOB_NOT_EXIST) {
			retVal = ID_ERR_NO_ERROR;
		}

		if (retVal == ID_ERR_NO_ERROR) {
			// CUPS http connect.
			if ((pHTTP = httpConnectEncrypt(serverName, ippPort(), cupsEncryption())) == NULL) {
				retVal = ID_ERR_CUPS_API_FAILED;
			}
			else {
				pRequest = ippNew();

				ippSetOperation(pRequest, IPP_CANCEL_JOB);
				ippSetRequestId(pRequest, 1);

				pLanguage = bjcupsLangDefault();		// cupsLangDefault() -> bjcupsLangDefault() for cups-1.1.19

				ippAddString(pRequest, IPP_TAG_OPERATION, IPP_TAG_CHARSET, "attributes-charset", NULL, cupsLangEncoding(pLanguage));
				ippAddString(pRequest, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE, "attributes-natural-language", NULL, pLanguage->language);
				ippAddString(pRequest, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, printerURI);
				ippAddInteger(pRequest, IPP_TAG_OPERATION, IPP_TAG_INTEGER, "job-id", jobID);
				ippAddString(pRequest, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name", NULL, cupsUser());

				if ((pResponse = cupsDoRequest(pHTTP, pRequest, "/jobs/")) != NULL) {
					if (ippGetStatusCode(pResponse) > IPP_OK_CONFLICT) {
						retVal = ID_ERR_CUPS_API_FAILED;
					}
					ippDelete(pResponse);
				}
				else {
					retVal = ID_ERR_CUPS_API_FAILED;
				}

				cupsLangFree(pLanguage);
				httpClose(pHTTP);
			}
		}
	}

	return(retVal);
}// End removeJob
Пример #5
0
void OnlineAstrometryParser::onResult(QNetworkReply* reply)
{
    bool ok;
    QJsonParseError parseError;
    QString status;
    QList<QVariant> jsonArray;
    int elapsed;

    if (workflowStage == NO_STAGE)
    {
        reply->abort();
        return;
    }

    if (reply->error() != QNetworkReply::NoError)
    {
        align->appendLogText(reply->errorString());
        emit solverFailed();
        return;
    }

    QString json = (QString) reply->readAll();

    QJsonDocument json_doc = QJsonDocument::fromJson(json.toUtf8(), &parseError);

     if (parseError.error != QJsonParseError::NoError)
     {
         align->appendLogText(i18n("JSon error during parsing (%1).", parseError.errorString()));
         emit solverFailed();
         return;
     }

     QVariant json_result = json_doc.toVariant();
     QVariantMap result = json_result.toMap();

     if (Options::solverVerbose())
         align->appendLogText(json_doc.toJson(QJsonDocument::Compact));

     switch (workflowStage)
     {
        case AUTH_STAGE:
         status = result["status"].toString();
         if (status != "success")
         {
             align->appendLogText(i18n("Astrometry.net authentication failed. Check the validity of the Astrometry.net API Key."));
             emit solverFailed();
             return;
         }

         sessionKey = result["session"].toString();

         if (Options::solverVerbose())
            align->appendLogText(i18n("Authentication to astrometry.net is successful. Session: %1", sessionKey));

         emit authenticateFinished();
         break;

       case UPLOAD_STAGE:
         status = result["status"].toString();
         if (status != "success")
         {
             align->appendLogText(i18n("Upload failed."));
             emit solverFailed();
             return;
         }

         subID = result["subid"].toInt(&ok);

         if (ok == false)
         {
             align->appendLogText(i18n("Parsing submission ID failed."));
             emit solverFailed();
             return;
         }

         align->appendLogText(i18n("Upload complete. Waiting for astrometry.net solver to complete..."));
         emit uploadFinished();
         if (isGenerated)
            QFile::remove(filename);
         break;

       case JOB_ID_STAGE:
         jsonArray = result["jobs"].toList();

         if (jsonArray.isEmpty())
             jobID = 0;
         else
             jobID = jsonArray.first().toInt(&ok);

         if (jobID == 0 || !ok)
         {
             if (job_retries++ < JOB_RETRY_ATTEMPTS)
             {
                QTimer::singleShot(JOB_RETRY_DURATION, this, SLOT(getJobID()));
                return;
             }
             else
             {
                 align->appendLogText(i18n("Failed to retrieve job ID."));
                 emit solverFailed();
                 return;
             }
         }

         job_retries=0;
         emit  jobIDFinished();
         break;

       case JOB_STATUS_STAGE:
         status = result["status"].toString();
         if (status == "success")
             emit jobFinished();
         else if (status == "solving")
         {
             if (status == "solving" && solver_retries++ < SOLVER_RETRY_ATTEMPTS)
             {
                QTimer::singleShot(SOLVER_RETRY_DURATION, this, SLOT(checkJobs()));
                return;
             }
             else
             {
                 align->appendLogText(i18n("Solver timed out."));
                 solver_retries=0;
                 emit solverFailed();
                 return;
             }
         }
         else if (status == "failure")
         {
             elapsed = (int) round(solverTimer.elapsed()/1000.0);
             align->appendLogText(i18np("Solver failed after %1 second.", "Solver failed after %1 seconds.", elapsed));
             emit solverFailed();
             return;
         }
         break;

     case JOB_CALIBRATION_STAGE:
         parity = result["parity"].toInt(&ok);
         if (ok == false)
         {
             align->appendLogText(i18n("Error parsing parity."));
             emit solverFailed();
             return;
         }
         orientation = result["orientation"].toDouble(&ok);
         if (ok == false)
         {
             align->appendLogText(i18n("Error parsing orientation."));
             emit solverFailed();
             return;
         }
         orientation *= parity;
         ra  = result["ra"].toDouble(&ok);
         if (ok == false)
         {
             align->appendLogText(i18n("Error parsing RA."));
             emit solverFailed();
             return;
         }
         dec = result["dec"].toDouble(&ok);
         if (ok == false)
         {
             align->appendLogText(i18n("Error parsing DEC."));
             emit solverFailed();
             return;
         }

         pixscale = result["pixscale"].toDouble(&ok);
         if (ok == false)
         {
             align->appendLogText(i18n("Error parsing DEC."));
             emit solverFailed();
             return;
         }

         elapsed = (int) round(solverTimer.elapsed()/1000.0);
         align->appendLogText(i18np("Solver completed in %1 second.", "Solver completed in %1 seconds.", elapsed));
         emit solverFinished(orientation, ra, dec, pixscale);

         break;

     default:
         break;
     }

}