use of org.w3._2007.rif.If in project airavata by apache.
the class BESJobSubmissionTask method execute.
@Override
public TaskStatus execute(TaskContext taskContext) {
TaskStatus taskStatus = new TaskStatus(TaskState.CREATED);
StorageClient sc = null;
ProcessContext processContext = taskContext.getParentProcessContext();
// FIXME - use original output dir
setInputOutputLocations(processContext);
try {
// con't reuse if UserDN has been changed.
secProperties = getSecurityConfig(processContext);
// try secProperties = secProperties.clone() if we can't use already initialized ClientConfigurations.
} catch (GFacException e) {
String msg = "Unicorn security context initialization error";
log.error(msg, e);
taskStatus.setState(TaskState.FAILED);
taskStatus.setReason(msg);
return taskStatus;
}
try {
JobSubmissionProtocol protocol = processContext.getJobSubmissionProtocol();
JobSubmissionInterface jobSubmissionInterface = GFacUtils.getPreferredJobSubmissionInterface(processContext);
String factoryUrl = null;
if (protocol.equals(JobSubmissionProtocol.UNICORE)) {
UnicoreJobSubmission unicoreJobSubmission = GFacUtils.getUnicoreJobSubmission(jobSubmissionInterface.getJobSubmissionInterfaceId());
factoryUrl = unicoreJobSubmission.getUnicoreEndPointURL();
}
EndpointReferenceType eprt = EndpointReferenceType.Factory.newInstance();
eprt.addNewAddress().setStringValue(factoryUrl);
String userDN = processContext.getProcessModel().getUserDn();
CreateActivityDocument cad = CreateActivityDocument.Factory.newInstance();
// create storage
StorageCreator storageCreator = new StorageCreator(secProperties, factoryUrl, 5, null);
sc = storageCreator.createStorage();
JobDefinitionType jobDefinition = JSDLGenerator.buildJSDLInstance(processContext, sc.getUrl()).getJobDefinition();
cad.addNewCreateActivity().addNewActivityDocument().setJobDefinition(jobDefinition);
log.info("Submitted JSDL: " + jobDefinition.getJobDescription());
// copy files to local
copyInputFilesToLocal(taskContext);
// upload files if any
DataTransferrer dt = new DataTransferrer(processContext, sc);
dt.uploadLocalFiles();
JobModel jobDetails = new JobModel();
jobDetails.setTaskId(taskContext.getTaskId());
jobDetails.setProcessId(taskContext.getProcessId());
FactoryClient factory = new FactoryClient(eprt, secProperties);
log.info("Activity Submitting to {} ... \n", factoryUrl);
CreateActivityResponseDocument response = factory.createActivity(cad);
log.info("Activity Submitted to {} ... \n", factoryUrl);
EndpointReferenceType activityEpr = response.getCreateActivityResponse().getActivityIdentifier();
log.info("Activity : " + activityEpr.getAddress().getStringValue() + " Submitted.");
// factory.waitWhileActivityIsDone(activityEpr, 1000);
jobId = WSUtilities.extractResourceID(activityEpr);
if (jobId == null) {
jobId = new Long(Calendar.getInstance().getTimeInMillis()).toString();
}
log.info("JobID: " + jobId);
jobDetails.setJobId(jobId);
jobDetails.setJobDescription(activityEpr.toString());
jobDetails.setJobStatuses(Arrays.asList(new JobStatus(JobState.SUBMITTED)));
processContext.setJobModel(jobDetails);
GFacUtils.saveJobModel(processContext, jobDetails);
GFacUtils.saveJobStatus(processContext, jobDetails);
log.info(formatStatusMessage(activityEpr.getAddress().getStringValue(), factory.getActivityStatus(activityEpr).toString()));
waitUntilDone(eprt, activityEpr, processContext, secProperties);
ActivityStatusType activityStatus = null;
activityStatus = getStatus(factory, activityEpr);
log.info(formatStatusMessage(activityEpr.getAddress().getStringValue(), activityStatus.getState().toString()));
ActivityClient activityClient;
activityClient = new ActivityClient(activityEpr, secProperties);
// now use the activity working directory property
dt.setStorageClient(activityClient.getUspaceClient());
List<OutputDataObjectType> copyOutput = null;
if ((activityStatus.getState() == ActivityStateEnumeration.FAILED)) {
String error = activityStatus.getFault().getFaultcode().getLocalPart() + "\n" + activityStatus.getFault().getFaultstring() + "\n EXITCODE: " + activityStatus.getExitCode();
log.error(error);
JobState applicationJobStatus = JobState.FAILED;
jobDetails.setJobStatuses(Arrays.asList(new JobStatus(applicationJobStatus)));
sendNotification(processContext, jobDetails);
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
}
// What if job is failed before execution and there are not stdouts generated yet?
log.debug("Downloading any standard output and error files, if they were produced.");
copyOutput = dt.downloadRemoteFiles();
} else if (activityStatus.getState() == ActivityStateEnumeration.CANCELLED) {
JobState applicationJobStatus = JobState.CANCELED;
jobDetails.setJobStatuses(Arrays.asList(new JobStatus(applicationJobStatus)));
GFacUtils.saveJobStatus(processContext, jobDetails);
throw new GFacException(processContext.getExperimentId() + "Job Canceled");
} else if (activityStatus.getState() == ActivityStateEnumeration.FINISHED) {
try {
Thread.sleep(5000);
} catch (InterruptedException ignored) {
}
JobState applicationJobStatus = JobState.COMPLETE;
jobDetails.setJobStatuses(Arrays.asList(new JobStatus(applicationJobStatus)));
GFacUtils.saveJobStatus(processContext, jobDetails);
log.info("Job Id: {}, exit code: {}, exit status: {}", jobDetails.getJobId(), activityStatus.getExitCode(), ActivityStateEnumeration.FINISHED.toString());
// if (activityStatus.getExitCode() == 0) {
// } else {
// dt.downloadStdOuts();
// }
copyOutput = dt.downloadRemoteFiles();
}
if (copyOutput != null) {
copyOutputFilesToStorage(taskContext, copyOutput);
for (OutputDataObjectType outputDataObjectType : copyOutput) {
GFacUtils.saveExperimentOutput(processContext, outputDataObjectType.getName(), outputDataObjectType.getValue());
}
}
// dt.publishFinalOutputs();
taskStatus.setState(TaskState.COMPLETED);
} catch (AppCatalogException e) {
log.error("Error while retrieving UNICORE job submission..", e);
taskStatus.setState(TaskState.FAILED);
} catch (Exception e) {
log.error("BES task failed... ", e);
taskStatus.setState(TaskState.FAILED);
}
return taskStatus;
}
use of org.w3._2007.rif.If in project airavata by apache.
the class AbstractSMSHandler method invoke.
@Override
public void invoke(JobExecutionContext jobExecutionContext) throws GFacHandlerException {
try {
initSecurityProperties(jobExecutionContext);
JobSubmissionInterface preferredJobSubmissionInterface = jobExecutionContext.getPreferredJobSubmissionInterface();
JobSubmissionProtocol protocol = preferredJobSubmissionInterface.getJobSubmissionProtocol();
String interfaceId = preferredJobSubmissionInterface.getJobSubmissionInterfaceId();
String factoryUrl = null;
if (protocol.equals(JobSubmissionProtocol.UNICORE)) {
UnicoreJobSubmission unicoreJobSubmission = GFacUtils.getUnicoreJobSubmission(interfaceId);
factoryUrl = unicoreJobSubmission.getUnicoreEndPointURL();
}
storageClient = null;
if (!isSMSInstanceExisting(jobExecutionContext)) {
EndpointReferenceType eprt = EndpointReferenceType.Factory.newInstance();
eprt.addNewAddress().setStringValue(factoryUrl);
StorageCreator storageCreator = new StorageCreator(secProperties, factoryUrl, 5, null);
try {
storageClient = storageCreator.createStorage();
} catch (Exception e2) {
log.error("Cannot create storage..");
throw new GFacHandlerException("Cannot create storage..", e2);
}
jobExecutionContext.setProperty(PROP_SMS_EPR, storageClient.getEPR());
} else {
EndpointReferenceType eprt = (EndpointReferenceType) jobExecutionContext.getProperty(PROP_SMS_EPR);
try {
storageClient = new StorageClient(eprt, secProperties);
} catch (Exception e) {
throw new GFacHandlerException("Cannot create storage..", e);
}
}
dataTransferrer = new DataTransferrer(jobExecutionContext, storageClient);
} catch (AppCatalogException e) {
throw new GFacHandlerException("Error occurred while retrieving unicore job submission interface..", e);
}
}
use of org.w3._2007.rif.If in project airavata by apache.
the class StorageCreator method findServerName.
protected String findServerName(String besUrl, EndpointReferenceType smsEpr) throws Exception {
int besIndex = besUrl.indexOf("StorageFactory?res");
String ss = besUrl.substring(0, besIndex);
ss = ss + "Registry";
EndpointReferenceType eprt = WSUtilities.makeServiceEPR(ss, "default_registry", Registry.REGISTRY_PORT);
RegistryClient registry = new RegistryClient(eprt, secProps);
// first, check if server name is already in the EPR...
String dn = WSUtilities.extractServerIDFromEPR(smsEpr);
if (dn != null) {
return dn;
}
// otherwise find a matching service in the registry
String url = smsEpr.getAddress().getStringValue();
if (url.contains("/services/"))
url = url.substring(0, url.indexOf("/services"));
if (log.isDebugEnabled())
log.debug("Checking for services at " + url);
for (EntryType entry : registry.listEntries()) {
if (entry.getMemberServiceEPR().getAddress().getStringValue().startsWith(url)) {
dn = WSUtilities.extractServerIDFromEPR(entry.getMemberServiceEPR());
if (dn != null) {
return dn;
}
}
}
return null;
}
use of org.w3._2007.rif.If in project webcert by sklintyg.
the class FragaSvarServiceImpl method saveNewQuestion.
@Override
public FragaSvar saveNewQuestion(String intygId, String typ, Amne amne, String frageText) {
// Argument check
if (Strings.isNullOrEmpty(frageText)) {
throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "frageText cannot be empty!");
}
if (amne == null) {
throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "Amne cannot be null!");
} else if (!VALID_VARD_AMNEN.contains(amne)) {
// Businessrule RE-013
throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "Invalid Amne " + amne + " for new question from vard!");
}
// Fetch from Intygstjansten. Note that if Intygstjansten is unresponsive, the Intyg will be loaded from WebCert
// if possible.
IntygContentHolder intyg = intygService.fetchIntygData(intygId, typ, false);
WebCertUser user = webCertUserService.getUser();
// Get vardperson that posed the question
// Is user authorized to save an answer to this question?
verifyEnhetsAuth(intyg.getUtlatande().getGrundData().getSkapadAv().getVardenhet().getEnhetsid(), false);
// Verksamhetsregel FS-001 (Is the certificate sent to FK)
if (!isCertificateSentToFK(intyg.getStatuses())) {
throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "FS-001: Certificate must be sent to FK first before sending question!");
}
// Verify that certificate is not revoked
if (intyg.isRevoked()) {
throw new WebCertServiceException(WebCertServiceErrorCodeEnum.INTERNAL_PROBLEM, "FS-XXX: Cannot save Fraga when certificate is revoked!");
}
IntygsReferens intygsReferens = FragaSvarConverter.convertToIntygsReferens(intyg.getUtlatande());
HoSPersonal hoSPersonal = IntygConverterUtil.buildHosPersonalFromWebCertUser(user, null);
Vardperson vardPerson = FragaSvarConverter.convert(hoSPersonal);
FragaSvar fraga = new FragaSvar();
fraga.setFrageStallare(FrageStallare.WEBCERT.getKod());
fraga.setAmne(amne);
fraga.setFrageText(frageText);
LocalDateTime now = LocalDateTime.now();
fraga.setFrageSkickadDatum(now);
fraga.setFrageSigneringsDatum(now);
fraga.setIntygsReferens(intygsReferens);
fraga.setVardperson(vardPerson);
fraga.setStatus(Status.PENDING_EXTERNAL_ACTION);
fraga.setVardAktorHsaId(user.getHsaId());
fraga.setVardAktorNamn(user.getNamn());
// Ok, lets save the question
FragaSvar saved = fragaSvarRepository.save(fraga);
// Send to external party (FK)
SendMedicalCertificateQuestionType sendType = new SendMedicalCertificateQuestionType();
QuestionToFkType question = FKQuestionConverter.convert(saved);
// Remove ASAP.
if ("true".equalsIgnoreCase(forceFullstandigtNamn)) {
question.getLakarutlatande().getPatient().setFullstandigtNamn("---");
}
sendType.setQuestion(question);
AttributedURIType logicalAddress = new AttributedURIType();
logicalAddress.setValue(sendQuestionToFkLogicalAddress);
SendMedicalCertificateQuestionResponseType response;
try {
response = sendQuestionToFKClient.sendMedicalCertificateQuestion(logicalAddress, sendType);
} catch (SOAPFaultException e) {
LOGGER.error("Failed to send question to FK, error was: " + e.getMessage());
throw new WebCertServiceException(WebCertServiceErrorCodeEnum.EXTERNAL_SYSTEM_PROBLEM, e.getMessage());
}
if (!response.getResult().getResultCode().equals(ResultCodeEnum.OK)) {
LOGGER.error("Failed to send question to FK, result was " + response.getResult().toString());
throw new WebCertServiceException(WebCertServiceErrorCodeEnum.EXTERNAL_SYSTEM_PROBLEM, response.getResult().getErrorText());
}
monitoringService.logQuestionSent(saved.getExternReferens(), saved.getInternReferens(), (saved.getIntygsReferens() == null) ? null : saved.getIntygsReferens().getIntygsId(), saved.getVardAktorHsaId(), saved.getAmne());
// Notify stakeholders
sendNotification(saved, NotificationEvent.NEW_QUESTION_FROM_CARE);
arendeDraftService.delete(intygId, null);
return saved;
}
use of org.w3._2007.rif.If in project arctic-sea by 52North.
the class Soap12Decoder method getBodyContent.
private OwsServiceRequest getBodyContent(EnvelopeDocument doc) throws DecodingException {
Body body = doc.getEnvelope().getBody();
try {
Node domNode = body.getDomNode();
if (domNode.hasChildNodes()) {
NodeList childNodes = domNode.getChildNodes();
for (int i = 0; i < childNodes.getLength(); i++) {
Node node = childNodes.item(i);
if (node.getNodeType() == Node.ELEMENT_NODE) {
XmlObject content = XmlObject.Factory.parse(node);
// fix problem with invalid prefix in xsi:type value for
// om:result, e.g. OM_SWEArrayObservation or
// gml:ReferenceType
Map<?, ?> namespaces = XmlHelper.getNamespaces(doc.getEnvelope());
fixNamespaceForXsiType(content, namespaces);
XmlHelper.fixNamespaceForXsiType(content, SweConstants.QN_DATA_ARRAY_PROPERTY_TYPE_SWE_200);
return decodeXmlElement(content);
}
}
}
return decodeXmlElement(body);
} catch (XmlException xmle) {
throw new DecodingException("Error while parsing SOAP body element!", xmle);
}
}
Aggregations