Search in sources :

Example 1 with UriDeploymentHttpScanner

use of org.apache.ignite.spi.deployment.uri.scanners.http.UriDeploymentHttpScanner 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)

Aggregations

File (java.io.File)1 FilenameFilter (java.io.FilenameFilter)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 IgniteInterruptedCheckedException (org.apache.ignite.internal.IgniteInterruptedCheckedException)1 IgniteSpiException (org.apache.ignite.spi.IgniteSpiException)1 GridUriDeploymentScannerListener (org.apache.ignite.spi.deployment.uri.scanners.GridUriDeploymentScannerListener)1 UriDeploymentScanner (org.apache.ignite.spi.deployment.uri.scanners.UriDeploymentScanner)1 UriDeploymentScannerManager (org.apache.ignite.spi.deployment.uri.scanners.UriDeploymentScannerManager)1 UriDeploymentFileScanner (org.apache.ignite.spi.deployment.uri.scanners.file.UriDeploymentFileScanner)1 UriDeploymentHttpScanner (org.apache.ignite.spi.deployment.uri.scanners.http.UriDeploymentHttpScanner)1