Search in sources :

Example 61 with IgniteSpiException

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;
}
Also used : BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) File(java.io.File) FileInputStream(java.io.FileInputStream) Nullable(org.jetbrains.annotations.Nullable)

Example 62 with IgniteSpiException

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());
}
Also used : UriDeploymentFileScanner(org.apache.ignite.spi.deployment.uri.scanners.file.UriDeploymentFileScanner) URI(java.net.URI) UriDeploymentHttpScanner(org.apache.ignite.spi.deployment.uri.scanners.http.UriDeploymentHttpScanner) FilenameFilter(java.io.FilenameFilter) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) UriDeploymentScanner(org.apache.ignite.spi.deployment.uri.scanners.UriDeploymentScanner) UriDeploymentScannerManager(org.apache.ignite.spi.deployment.uri.scanners.UriDeploymentScannerManager) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) File(java.io.File) GridUriDeploymentScannerListener(org.apache.ignite.spi.deployment.uri.scanners.GridUriDeploymentScannerListener)

Example 63 with IgniteSpiException

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);
    }
}
Also used : URISyntaxException(java.net.URISyntaxException) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) URI(java.net.URI)

Example 64 with IgniteSpiException

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);
}
Also used : IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) FileFilter(java.io.FileFilter) File(java.io.File)

Example 65 with IgniteSpiException

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);
}
Also used : MalformedURLException(java.net.MalformedURLException) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) SSLContext(javax.net.ssl.SSLContext) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) SSLSocketFactory(javax.net.ssl.SSLSocketFactory) URL(java.net.URL) KeyManagementException(java.security.KeyManagementException)

Aggregations

IgniteSpiException (org.apache.ignite.spi.IgniteSpiException)131 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)59 IOException (java.io.IOException)32 InetSocketAddress (java.net.InetSocketAddress)22 ClusterNode (org.apache.ignite.cluster.ClusterNode)21 IgniteInterruptedCheckedException (org.apache.ignite.internal.IgniteInterruptedCheckedException)21 IgniteException (org.apache.ignite.IgniteException)20 ArrayList (java.util.ArrayList)14 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)14 HashMap (java.util.HashMap)13 UUID (java.util.UUID)13 Nullable (org.jetbrains.annotations.Nullable)12 Test (org.junit.Test)12 File (java.io.File)10 Message (org.apache.ignite.plugin.extensions.communication.Message)10 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)9 SSLException (javax.net.ssl.SSLException)8 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)8 SocketTimeoutException (java.net.SocketTimeoutException)7 Ignite (org.apache.ignite.Ignite)7