use of org.apache.ignite.spi.IgniteSpiException in project ignite by apache.
the class GridUriDeploymentFileProcessor method processFile.
/**
* Method processes given package and extracts all tasks from it which are
* either mentioned in a task descriptor or implement interface {@link org.apache.ignite.compute.ComputeTask}
* if there is no descriptor in file.
*
* @param file Package file with tasks.
* @param uri URI of the package.
* @param deployDir deployment directory with downloaded files.
* @param log Logger.
* @throws org.apache.ignite.spi.IgniteSpiException Thrown if file could not be read.
* @return List of tasks from given file.
*/
@Nullable
static GridUriDeploymentFileProcessorResult processFile(File file, String uri, File deployDir, IgniteLogger log) throws IgniteSpiException {
File pkg = file;
if (!checkIntegrity(file, log)) {
U.error(log, "Failed to load tasks from a package (invalid file signature) [uri=" + U.hidePassword(uri) + ']');
return null;
}
if (!file.isDirectory()) {
pkg = new File(deployDir, "dirzip_" + file.getName());
pkg.mkdirs();
try {
U.unzip(file, pkg, log);
} catch (IOException e) {
throw new IgniteSpiException("IO error when unzipping a package: " + file.getAbsolutePath(), e);
}
}
GridUriDeploymentFileProcessorResult res = null;
if (pkg.isDirectory()) {
try {
File xml = new File(pkg, XML_DESCRIPTOR_PATH);
if (!xml.exists() || xml.isDirectory()) {
U.warn(log, "Processing deployment without descriptor file (it will cause full classpath scan) [path=" + XML_DESCRIPTOR_PATH + ", package=" + pkg.getAbsolutePath() + ']');
res = processNoDescriptorFile(pkg, uri, log);
} else {
InputStream in = null;
try {
in = new BufferedInputStream(new FileInputStream(xml));
// Parse XML task definitions and add them to cache.
GridUriDeploymentSpringDocument doc = GridUriDeploymentSpringParser.parseTasksDocument(in, log);
assert doc != null;
res = processWithDescriptorFile(doc, pkg, uri, log);
} finally {
U.close(in, log);
}
}
} catch (IOException e) {
throw new IgniteSpiException("IO error when parsing a package: " + pkg.getAbsolutePath(), e);
}
}
if (res != null)
res.setMd5(md5(pkg, log));
return res;
}
use of org.apache.ignite.spi.IgniteSpiException in project ignite by apache.
the class UriDeploymentSpi method spiStart.
/**
* {@inheritDoc}
*/
@Override
public void spiStart(String igniteInstanceName) throws IgniteSpiException {
// Start SPI start stopwatch.
startStopwatch();
assertParameter(uriList != null, "uriList != null");
initializeUriList();
if (uriEncodedList.isEmpty())
addDefaultUri();
initializeTemporaryDirectoryPath();
registerMBean(igniteInstanceName, new UriDeploymentSpiMBeanImpl(this), UriDeploymentSpiMBean.class);
FilenameFilter filter = new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
assert name != null;
String nameLowerCase = name.toLowerCase();
return nameLowerCase.endsWith(".gar") || nameLowerCase.endsWith(".jar");
}
};
firstScanCntr = 0;
GridUriDeploymentScannerListener lsnr = new GridUriDeploymentScannerListener() {
@Override
public void onNewOrUpdatedFile(File file, String uri, long tstamp) {
if (log.isInfoEnabled())
log.info("Found new or updated deployment unit [uri=" + U.hidePassword(uri) + ", file=" + file.getAbsolutePath() + ", tstamp=" + tstamp + ']');
if (delayOnNewOrUpdatedFile) {
U.warn(log, "Delaying onNewOrUpdatedFile() by 10000 ms since 'delayOnNewOrUpdatedFile' " + "is set to true (is this intentional?).");
try {
U.sleep(10000);
} catch (IgniteInterruptedCheckedException ignored) {
// No-op
}
U.warn(log, "Delay finished.");
}
try {
GridUriDeploymentFileProcessorResult fileRes = GridUriDeploymentFileProcessor.processFile(file, uri, new File(deployTmpDirPath), log);
if (fileRes != null)
newUnitReceived(uri, fileRes.getFile(), tstamp, fileRes.getClassLoader(), fileRes.getTaskClasses(), fileRes.getMd5());
} catch (IgniteSpiException e) {
U.error(log, "Error when processing file: " + file.getAbsolutePath(), e);
}
}
/**
* {@inheritDoc}
*/
@Override
public void onDeletedFiles(List<String> uris) {
if (log.isInfoEnabled()) {
List<String> uriList = null;
if (uris != null) {
uriList = new ArrayList<>();
for (String uri : uris) uriList.add(U.hidePassword(uri));
}
if (log.isInfoEnabled())
log.info("Found deleted deployment units [uris=" + uriList + ']');
}
processDeletedFiles(uris);
}
/**
* {@inheritDoc}
*/
@Override
public void onFirstScanFinished() {
synchronized (mux) {
firstScanCntr++;
if (isFirstScanFinished(firstScanCntr))
mux.notifyAll();
}
}
};
// Set default scanners if none are configured.
if (scanners == null) {
scanners = new UriDeploymentScanner[2];
scanners[0] = new UriDeploymentFileScanner();
scanners[1] = new UriDeploymentHttpScanner();
}
for (URI uri : uriEncodedList) {
File file = new File(deployTmpDirPath);
long freq = -1;
try {
freq = getFrequencyFromUri(uri);
} catch (NumberFormatException e) {
U.error(log, "Error parsing parameter value for frequency.", e);
}
UriDeploymentScannerManager mgr = null;
for (UriDeploymentScanner scanner : scanners) {
if (scanner.acceptsURI(uri)) {
mgr = new UriDeploymentScannerManager(igniteInstanceName, uri, file, freq > 0 ? freq : scanner.getDefaultScanFrequency(), filter, lsnr, log, scanner);
break;
}
}
if (mgr == null)
throw new IgniteSpiException("Unsupported URI (please configure appropriate scanner): " + uri);
mgrs.add(mgr);
mgr.start();
}
// Ack parameters.
if (log.isDebugEnabled()) {
log.debug(configInfo("tmpDirPath", tmpDirPath));
log.debug(configInfo("uriList", uriList));
log.debug(configInfo("encodeUri", encodeUri));
log.debug(configInfo("scanners", mgrs));
}
// Ack ok start.
if (log.isDebugEnabled())
log.debug(startInfo());
}
use of org.apache.ignite.spi.IgniteSpiException in project ignite by apache.
the class UriDeploymentSpi method initializeUriList.
/**
* Fills in list of URIs with all available URIs and encodes them if
* encoding is enabled.
*
* @throws org.apache.ignite.spi.IgniteSpiException Thrown if at least one URI has incorrect syntax.
*/
private void initializeUriList() throws IgniteSpiException {
for (String uri : uriList) {
assertParameter(uri != null, "uriList.get(X) != null");
String encUri = encodeUri(uri.replaceAll("\\\\", "/"));
URI uriObj;
try {
uriObj = new URI(encUri);
} catch (URISyntaxException e) {
throw new IgniteSpiException("Failed to parse URI [uri=" + U.hidePassword(uri) + ", encodedUri=" + U.hidePassword(encUri) + ']', e);
}
if (uriObj.getScheme() == null || uriObj.getScheme().trim().isEmpty())
throw new IgniteSpiException("Failed to get 'scheme' from URI [uri=" + U.hidePassword(uri) + ", encodedUri=" + U.hidePassword(encUri) + ']');
uriEncodedList.add(uriObj);
}
}
use of org.apache.ignite.spi.IgniteSpiException in project ignite by apache.
the class UriDeploymentFileScanner method createUriContext.
/**
* Create context for the given URI.
*
* @param uri URI.
* @param scanCtx Scanner context.
* @return URI context.
*/
private URIContext createUriContext(URI uri, final UriDeploymentScannerContext scanCtx) {
String scanDirPath = uri.getPath();
File scanDir = null;
if (scanDirPath != null)
scanDir = new File(scanDirPath);
if (scanDir == null || !scanDir.isDirectory())
throw new IgniteSpiException("URI is either not provided or is not a directory: " + U.hidePassword(uri.toString()));
FileFilter pkgFilter = new FileFilter() {
/**
* {@inheritDoc}
*/
@Override
public boolean accept(File pathname) {
return scanCtx.getFilter().accept(null, pathname.getName());
}
};
FileFilter pkgDirFilesFilter = new FileFilter() {
/**
* {@inheritDoc}
*/
@Override
public boolean accept(File pathname) {
// Allow all files in package.
return pathname.isFile();
}
};
return new URIContext(scanDir, pkgFilter, pkgDirFilesFilter);
}
use of org.apache.ignite.spi.IgniteSpiException in project ignite by apache.
the class UriDeploymentHttpScanner method createUriContext.
/**
* Create context for the given URI.
*
* @param uri URI.
* @param scanCtx Scanner context.
* @return URI context.
*/
private URIContext createUriContext(URI uri, final UriDeploymentScannerContext scanCtx) {
assert "http".equals(uri.getScheme()) || "https".equals(uri.getScheme());
URL scanDir;
try {
scanDir = new URL(uri.getScheme(), uri.getHost(), uri.getPort(), uri.getPath());
} catch (MalformedURLException e) {
throw new IgniteSpiException("Wrong value for scanned HTTP directory with URI: " + uri, e);
}
SSLSocketFactory sockFactory = null;
try {
if ("https".equals(uri.getScheme())) {
// Set up socket factory to do authentication.
SSLContext ctx = SSLContext.getInstance(PROTOCOL);
ctx.init(null, getTrustManagers(scanCtx), null);
sockFactory = ctx.getSocketFactory();
}
} catch (NoSuchAlgorithmException e) {
throw new IgniteSpiException("Failed to initialize SSL context. URI: " + uri, e);
} catch (KeyManagementException e) {
throw new IgniteSpiException("Failed to initialize SSL context. URI:" + uri, e);
}
return new URIContext(scanDir, sockFactory);
}
Aggregations