use of org.apache.oozie.service.HadoopAccessorException in project oozie by apache.
the class JavaActionExecutor method setupLauncherConf.
Configuration setupLauncherConf(Configuration conf, Element actionXml, Path appPath, Context context) throws ActionExecutorException {
try {
Namespace ns = actionXml.getNamespace();
XConfiguration launcherConf = new XConfiguration();
// Inject action defaults for launcher
HadoopAccessorService has = Services.get().get(HadoopAccessorService.class);
XConfiguration actionDefaultConf = has.createActionDefaultConf(conf.get(HADOOP_YARN_RM), getType());
new LauncherConfigurationInjector(actionDefaultConf).inject(launcherConf);
// Inject <job-xml> and <configuration> for launcher
try {
parseJobXmlAndConfiguration(context, actionXml, appPath, launcherConf, true);
} catch (HadoopAccessorException ex) {
throw convertException(ex);
} catch (URISyntaxException ex) {
throw convertException(ex);
}
XConfiguration.copy(launcherConf, conf);
// Inject config-class for launcher to use for action
Element e = actionXml.getChild("config-class", ns);
if (e != null) {
conf.set(LauncherAMUtils.OOZIE_ACTION_CONFIG_CLASS, e.getTextTrim());
}
checkForDisallowedProps(launcherConf, "launcher configuration");
return conf;
} catch (IOException ex) {
throw convertException(ex);
}
}
use of org.apache.oozie.service.HadoopAccessorException in project oozie by apache.
the class JavaActionExecutor method parseJobXmlAndConfiguration.
public static void parseJobXmlAndConfiguration(Context context, Element element, Path appPath, Configuration conf, boolean isLauncher) throws IOException, ActionExecutorException, HadoopAccessorException, URISyntaxException {
Namespace ns = element.getNamespace();
@SuppressWarnings("unchecked") Iterator<Element> it = element.getChildren("job-xml", ns).iterator();
HashMap<String, FileSystem> filesystemsMap = new HashMap<String, FileSystem>();
HadoopAccessorService has = Services.get().get(HadoopAccessorService.class);
while (it.hasNext()) {
Element e = it.next();
String jobXml = e.getTextTrim();
Path pathSpecified = new Path(jobXml);
Path path = pathSpecified.isAbsolute() ? pathSpecified : new Path(appPath, jobXml);
FileSystem fs;
if (filesystemsMap.containsKey(path.toUri().getAuthority())) {
fs = filesystemsMap.get(path.toUri().getAuthority());
} else {
if (path.toUri().getAuthority() != null) {
fs = has.createFileSystem(context.getWorkflow().getUser(), path.toUri(), has.createConfiguration(path.toUri().getAuthority()));
} else {
fs = context.getAppFileSystem();
}
filesystemsMap.put(path.toUri().getAuthority(), fs);
}
Configuration jobXmlConf = new XConfiguration(fs.open(path));
try {
String jobXmlConfString = XmlUtils.prettyPrint(jobXmlConf).toString();
jobXmlConfString = XmlUtils.removeComments(jobXmlConfString);
jobXmlConfString = context.getELEvaluator().evaluate(jobXmlConfString, String.class);
jobXmlConf = new XConfiguration(new StringReader(jobXmlConfString));
} catch (ELEvaluationException ex) {
throw new ActionExecutorException(ActionExecutorException.ErrorType.TRANSIENT, "EL_EVAL_ERROR", ex.getMessage(), ex);
} catch (Exception ex) {
context.setErrorInfo("EL_ERROR", ex.getMessage());
}
checkForDisallowedProps(jobXmlConf, "job-xml");
if (isLauncher) {
new LauncherConfigurationInjector(jobXmlConf).inject(conf);
} else {
XConfiguration.copy(jobXmlConf, conf);
}
}
Element e = element.getChild("configuration", ns);
if (e != null) {
String strConf = XmlUtils.prettyPrint(e).toString();
XConfiguration inlineConf = new XConfiguration(new StringReader(strConf));
checkForDisallowedProps(inlineConf, "inline configuration");
if (isLauncher) {
new LauncherConfigurationInjector(inlineConf).inject(conf);
} else {
XConfiguration.copy(inlineConf, conf);
}
}
}
use of org.apache.oozie.service.HadoopAccessorException in project oozie by apache.
the class JavaActionExecutor method addActionLibs.
protected void addActionLibs(Path appPath, Configuration conf) throws ActionExecutorException {
String[] actionLibsStrArr = conf.getStrings("oozie.launcher.oozie.libpath");
if (actionLibsStrArr != null) {
try {
for (String actionLibsStr : actionLibsStrArr) {
actionLibsStr = actionLibsStr.trim();
if (actionLibsStr.length() > 0) {
Path actionLibsPath = new Path(actionLibsStr);
String user = conf.get("user.name");
FileSystem fs = Services.get().get(HadoopAccessorService.class).createFileSystem(user, appPath.toUri(), conf);
if (fs.exists(actionLibsPath)) {
FileStatus[] files = fs.listStatus(actionLibsPath);
for (FileStatus file : files) {
addToCache(conf, appPath, file.getPath().toUri().getPath(), false);
}
}
}
}
} catch (HadoopAccessorException ex) {
throw new ActionExecutorException(ActionExecutorException.ErrorType.FAILED, ex.getErrorCode().toString(), ex.getMessage());
} catch (IOException ex) {
throw new ActionExecutorException(ActionExecutorException.ErrorType.FAILED, "It should never happen", ex.getMessage());
}
}
}
use of org.apache.oozie.service.HadoopAccessorException in project oozie by apache.
the class EmailActionExecutor method email.
public void email(String[] to, String[] cc, String[] bcc, String subject, String body, String[] attachments, String contentType, String user) throws ActionExecutorException {
// Get mailing server details.
String smtpHost = ConfigurationService.get(EMAIL_SMTP_HOST);
Integer smtpPortInt = ConfigurationService.getInt(EMAIL_SMTP_PORT);
Boolean smtpAuthBool = ConfigurationService.getBoolean(EMAIL_SMTP_AUTH);
String smtpUser = ConfigurationService.get(EMAIL_SMTP_USER);
String smtpPassword = ConfigurationService.getPassword(EMAIL_SMTP_PASS, "");
String fromAddr = ConfigurationService.get(EMAIL_SMTP_FROM);
Integer timeoutMillisInt = ConfigurationService.getInt(EMAIL_SMTP_SOCKET_TIMEOUT_MS);
Properties properties = new Properties();
properties.setProperty("mail.smtp.host", smtpHost);
properties.setProperty("mail.smtp.port", smtpPortInt.toString());
properties.setProperty("mail.smtp.auth", smtpAuthBool.toString());
// Apply sensible timeouts, as defaults are infinite. See https://s.apache.org/javax-mail-timeouts
properties.setProperty("mail.smtp.connectiontimeout", timeoutMillisInt.toString());
properties.setProperty("mail.smtp.timeout", timeoutMillisInt.toString());
properties.setProperty("mail.smtp.writetimeout", timeoutMillisInt.toString());
Session session;
// (cause it may lead to issues when used second time).
if (!smtpAuthBool) {
session = Session.getInstance(properties);
} else {
session = Session.getInstance(properties, new JavaMailAuthenticator(smtpUser, smtpPassword));
}
Message message = new MimeMessage(session);
InternetAddress from;
List<InternetAddress> toAddrs = new ArrayList<InternetAddress>(to.length);
List<InternetAddress> ccAddrs = new ArrayList<InternetAddress>(cc.length);
List<InternetAddress> bccAddrs = new ArrayList<InternetAddress>(bcc.length);
try {
from = new InternetAddress(fromAddr);
message.setFrom(from);
} catch (AddressException e) {
throw new ActionExecutorException(ErrorType.ERROR, "EM002", "Bad from address specified in ${oozie.email.from.address}.", e);
} catch (MessagingException e) {
throw new ActionExecutorException(ErrorType.ERROR, "EM003", "Error setting a from address in the message.", e);
}
try {
// Add all <to>
for (String toStr : to) {
toAddrs.add(new InternetAddress(toStr.trim()));
}
message.addRecipients(RecipientType.TO, toAddrs.toArray(new InternetAddress[0]));
// Add all <cc>
for (String ccStr : cc) {
ccAddrs.add(new InternetAddress(ccStr.trim()));
}
message.addRecipients(RecipientType.CC, ccAddrs.toArray(new InternetAddress[0]));
// Add all <bcc>
for (String bccStr : bcc) {
bccAddrs.add(new InternetAddress(bccStr.trim()));
}
message.addRecipients(RecipientType.BCC, bccAddrs.toArray(new InternetAddress[0]));
// Set subject
message.setSubject(subject);
// when there is attachment
if (attachments != null && attachments.length > 0 && ConfigurationService.getBoolean(EMAIL_ATTACHMENT_ENABLED)) {
Multipart multipart = new MimeMultipart();
// Set body text
MimeBodyPart bodyTextPart = new MimeBodyPart();
bodyTextPart.setText(body);
multipart.addBodyPart(bodyTextPart);
for (String attachment : attachments) {
URI attachUri = new URI(attachment);
if (attachUri.getScheme() != null && attachUri.getScheme().equals("file")) {
throw new ActionExecutorException(ErrorType.ERROR, "EM008", "Encountered an error when attaching a file. A local file cannot be attached:" + attachment);
}
MimeBodyPart messageBodyPart = new MimeBodyPart();
DataSource source = new URIDataSource(attachUri, user);
messageBodyPart.setDataHandler(new DataHandler(source));
messageBodyPart.setFileName(new File(attachment).getName());
multipart.addBodyPart(messageBodyPart);
}
message.setContent(multipart);
} else {
if (attachments != null && attachments.length > 0 && !ConfigurationService.getBoolean(EMAIL_ATTACHMENT_ENABLED)) {
body = body + EMAIL_ATTACHMENT_ERROR_MSG;
}
message.setContent(body, contentType);
}
} catch (AddressException e) {
throw new ActionExecutorException(ErrorType.ERROR, "EM004", "Bad address format in <to> or <cc> or <bcc>.", e);
} catch (MessagingException e) {
throw new ActionExecutorException(ErrorType.ERROR, "EM005", "An error occurred while adding recipients.", e);
} catch (URISyntaxException e) {
throw new ActionExecutorException(ErrorType.ERROR, "EM008", "Encountered an error when attaching a file", e);
} catch (HadoopAccessorException e) {
throw new ActionExecutorException(ErrorType.ERROR, "EM008", "Encountered an error when attaching a file", e);
}
try {
// Send over SMTP Transport
// (Session+Message has adequate details.)
Transport.send(message);
} catch (NoSuchProviderException e) {
throw new ActionExecutorException(ErrorType.ERROR, "EM006", "Could not find an SMTP transport provider to email.", e);
} catch (MessagingException e) {
throw new ActionExecutorException(ErrorType.ERROR, "EM007", "Encountered an error while sending the email message over SMTP.", e);
}
LOG.info("Email sent to [{0}]", to);
}
use of org.apache.oozie.service.HadoopAccessorException in project oozie by apache.
the class CoordSubmitXCommand method readDefinition.
/**
* Read coordinator definition.
*
* @param appPath application path.
* @return coordinator definition.
* @throws CoordinatorJobException thrown if the definition could not be read.
*/
protected String readDefinition(String appPath) throws CoordinatorJobException {
String user = ParamChecker.notEmpty(conf.get(OozieClient.USER_NAME), OozieClient.USER_NAME);
// Configuration confHadoop = CoordUtils.getHadoopConf(conf);
try {
URI uri = new URI(appPath);
LOG.debug("user =" + user);
HadoopAccessorService has = Services.get().get(HadoopAccessorService.class);
Configuration fsConf = has.createConfiguration(uri.getAuthority());
FileSystem fs = has.createFileSystem(user, uri, fsConf);
Path appDefPath = null;
// app path could be a directory
Path path = new Path(uri.getPath());
// check file exists for dataset include file, app xml already checked
if (!fs.exists(path)) {
throw new URISyntaxException(path.toString(), "path not existed : " + path.toString());
}
if (!fs.isFile(path)) {
appDefPath = new Path(path, COORDINATOR_XML_FILE);
} else {
appDefPath = path;
}
Reader reader = new InputStreamReader(fs.open(appDefPath));
StringWriter writer = new StringWriter();
IOUtils.copyCharStream(reader, writer);
return writer.toString();
} catch (IOException ex) {
LOG.warn("IOException :" + XmlUtils.prettyPrint(conf), ex);
throw new CoordinatorJobException(ErrorCode.E1001, ex.getMessage(), ex);
} catch (URISyntaxException ex) {
LOG.warn("URISyException :" + ex.getMessage());
throw new CoordinatorJobException(ErrorCode.E1002, appPath, ex.getMessage(), ex);
} catch (HadoopAccessorException ex) {
throw new CoordinatorJobException(ex);
} catch (Exception ex) {
LOG.warn("Exception :", ex);
throw new CoordinatorJobException(ErrorCode.E1001, ex.getMessage(), ex);
}
}
Aggregations