Search in sources :

Example 21 with IgniteInterruptedCheckedException

use of org.apache.ignite.internal.IgniteInterruptedCheckedException in project ignite by apache.

the class CacheHibernateBlobStore method init.

/**
     * Initializes store.
     *
     * @throws IgniteException If failed to initialize.
     */
private void init() throws IgniteException {
    if (initGuard.compareAndSet(false, true)) {
        if (log.isDebugEnabled())
            log.debug("Initializing cache store.");
        try {
            if (sesFactory != null)
                // Session factory has been provided - nothing to do.
                return;
            if (!F.isEmpty(hibernateCfgPath)) {
                try {
                    URL url = new URL(hibernateCfgPath);
                    sesFactory = new Configuration().configure(url).buildSessionFactory();
                    if (log.isDebugEnabled())
                        log.debug("Configured session factory using URL: " + url);
                    // Session factory has been successfully initialized.
                    return;
                } catch (MalformedURLException e) {
                    if (log.isDebugEnabled())
                        log.debug("Caught malformed URL exception: " + e.getMessage());
                }
                // Provided path is not a valid URL. File?
                File cfgFile = new File(hibernateCfgPath);
                if (cfgFile.exists()) {
                    sesFactory = new Configuration().configure(cfgFile).buildSessionFactory();
                    if (log.isDebugEnabled())
                        log.debug("Configured session factory using file: " + hibernateCfgPath);
                    // Session factory has been successfully initialized.
                    return;
                }
                // Provided path is not a file. Classpath resource?
                sesFactory = new Configuration().configure(hibernateCfgPath).buildSessionFactory();
                if (log.isDebugEnabled())
                    log.debug("Configured session factory using classpath resource: " + hibernateCfgPath);
            } else {
                if (hibernateProps == null) {
                    U.warn(log, "No Hibernate configuration has been provided for store (will use default).");
                    hibernateProps = new Properties();
                    hibernateProps.setProperty("hibernate.connection.url", DFLT_CONN_URL);
                    hibernateProps.setProperty("hibernate.show_sql", DFLT_SHOW_SQL);
                    hibernateProps.setProperty("hibernate.hbm2ddl.auto", DFLT_HBM2DDL_AUTO);
                }
                Configuration cfg = new Configuration();
                cfg.setProperties(hibernateProps);
                assert resourceAvailable(MAPPING_RESOURCE) : MAPPING_RESOURCE;
                cfg.addResource(MAPPING_RESOURCE);
                sesFactory = cfg.buildSessionFactory();
                if (log.isDebugEnabled())
                    log.debug("Configured session factory using properties: " + hibernateProps);
            }
        } catch (HibernateException e) {
            throw new IgniteException("Failed to initialize store.", e);
        } finally {
            initLatch.countDown();
        }
    } else if (initLatch.getCount() > 0) {
        try {
            U.await(initLatch);
        } catch (IgniteInterruptedCheckedException e) {
            throw new IgniteException(e);
        }
    }
    if (sesFactory == null)
        throw new IgniteException("Cache store was not properly initialized.");
}
Also used : IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) MalformedURLException(java.net.MalformedURLException) Configuration(org.hibernate.cfg.Configuration) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) HibernateException(org.hibernate.HibernateException) IgniteException(org.apache.ignite.IgniteException) Properties(java.util.Properties) File(java.io.File) URL(java.net.URL)

Example 22 with IgniteInterruptedCheckedException

use of org.apache.ignite.internal.IgniteInterruptedCheckedException in project ignite by apache.

the class TcpDiscoveryKubernetesIpFinder method init.

/**
     * Kubernetes IP finder initialization.
     *
     * @throws IgniteSpiException In case of error.
     */
private void init() throws IgniteSpiException {
    if (initGuard.compareAndSet(false, true)) {
        if (serviceName == null || serviceName.isEmpty() || namespace == null || namespace.isEmpty() || master == null || master.isEmpty() || accountToken == null || accountToken.isEmpty()) {
            throw new IgniteSpiException("One or more configuration parameters are invalid [setServiceName=" + serviceName + ", setNamespace=" + namespace + ", setMasterUrl=" + master + ", setAccountToken=" + accountToken + "]");
        }
        try {
            // Preparing the URL and SSL context to be used for connection purposes.
            String path = String.format("/api/v1/namespaces/%s/endpoints/%s", namespace, serviceName);
            url = new URL(master + path);
            ctx = SSLContext.getInstance("SSL");
            ctx.init(null, trustAll, new SecureRandom());
        } catch (Exception e) {
            throw new IgniteSpiException("Failed to connect to Ignite's Kubernetes Service.", e);
        } finally {
            initLatch.countDown();
        }
    } else {
        try {
            U.await(initLatch);
        } catch (IgniteInterruptedCheckedException e) {
            throw new IgniteSpiException("Thread has been interrupted.", e);
        }
        if (url == null || ctx == null)
            throw new IgniteSpiException("IP finder has not been initialized properly.");
    }
}
Also used : IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) SecureRandom(java.security.SecureRandom) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) URL(java.net.URL) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) IOException(java.io.IOException)

Example 23 with IgniteInterruptedCheckedException

use of org.apache.ignite.internal.IgniteInterruptedCheckedException in project ignite by apache.

the class GridTcpCommunicationSpiMultithreadedSelfTest method testFlowSend.

/**
     * @throws Exception If failed.
     */
public void testFlowSend() throws Exception {
    reject = true;
    final CyclicBarrier barrier = new CyclicBarrier(THREAD_CNT);
    final Random rnd = new Random();
    final ClusterNode from = randomNode(rnd);
    ClusterNode tmp;
    do {
        tmp = randomNode(rnd);
    } while (tmp.id().equals(from.id()));
    final ClusterNode to = tmp;
    final int iterationCnt = 1000;
    final AtomicInteger threadId = new AtomicInteger();
    final int interval = 50;
    IgniteInternalFuture<?> fut = multithreadedAsync(new Runnable() {

        /** {@inheritDoc} */
        @Override
        public void run() {
            try {
                // Only first thread will print messages.
                int id = threadId.getAndIncrement();
                for (int i = 0; i < iterationCnt; i++) {
                    if (id == 0 && (i % 50) == 0)
                        info(">>> Running iteration " + i);
                    try {
                        for (ClusterNode node : nodes) {
                            Message msg = new GridTestMessage(from.id(), msgId.getAndIncrement(), 0);
                            spis.get(from.id()).sendMessage(node, msg);
                        }
                    } catch (IgniteException e) {
                        log.warning(">>> Oops, unable to send message (safe to ignore).", e);
                    }
                    barrier.await();
                }
            } catch (InterruptedException ignored) {
                Thread.currentThread().interrupt();
            } catch (BrokenBarrierException e) {
                info("Wait on barrier failed: " + e);
                Thread.currentThread().interrupt();
            }
        }
    }, THREAD_CNT, "message-sender");
    final AtomicBoolean run = new AtomicBoolean(true);
    IgniteInternalFuture<?> fut2 = multithreadedAsync(new Runnable() {

        @Override
        public void run() {
            try {
                while (run.get() && !Thread.currentThread().isInterrupted()) {
                    U.sleep(interval * 3 / 2);
                    ((TcpCommunicationSpi) spis.get(from.id())).onNodeLeft(to.id());
                }
            } catch (IgniteInterruptedCheckedException ignored) {
                Thread.currentThread().interrupt();
            }
        }
    }, 1);
    fut.get();
    run.set(false);
    fut2.get();
    // Wait when all messages are acknowledged to do not break next tests' logic.
    for (CommunicationSpi<Message> spi : spis.values()) {
        GridNioServer srv = U.field(spi, "nioSrvr");
        Collection<? extends GridNioSession> sessions = GridTestUtils.getFieldValue(srv, "sessions");
        for (GridNioSession ses : sessions) {
            final GridNioRecoveryDescriptor snd = ses.outRecoveryDescriptor();
            if (snd != null) {
                GridTestUtils.waitForCondition(new GridAbsPredicate() {

                    @Override
                    public boolean apply() {
                        return snd.messagesRequests().isEmpty();
                    }
                }, 10_000);
                assertEquals("Unexpected messages: " + snd.messagesRequests(), 0, snd.messagesRequests().size());
            }
        }
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridTestMessage(org.apache.ignite.spi.communication.GridTestMessage) BrokenBarrierException(java.util.concurrent.BrokenBarrierException) GridTestMessage(org.apache.ignite.spi.communication.GridTestMessage) Message(org.apache.ignite.plugin.extensions.communication.Message) GridNioSession(org.apache.ignite.internal.util.nio.GridNioSession) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) GridNioServer(org.apache.ignite.internal.util.nio.GridNioServer) CyclicBarrier(java.util.concurrent.CyclicBarrier) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) Random(java.util.Random) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteException(org.apache.ignite.IgniteException) IgniteRunnable(org.apache.ignite.lang.IgniteRunnable) GridNioRecoveryDescriptor(org.apache.ignite.internal.util.nio.GridNioRecoveryDescriptor)

Example 24 with IgniteInterruptedCheckedException

use of org.apache.ignite.internal.IgniteInterruptedCheckedException 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;
            return name.toLowerCase().endsWith(".gar");
        }
    };
    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 GAR units [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));
                }
                log.info("Found deleted GAR 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) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) File(java.io.File) GridUriDeploymentScannerListener(org.apache.ignite.spi.deployment.uri.scanners.GridUriDeploymentScannerListener)

Example 25 with IgniteInterruptedCheckedException

use of org.apache.ignite.internal.IgniteInterruptedCheckedException in project ignite by apache.

the class CacheLockImpl method tryLock.

/** {@inheritDoc} */
@Override
public boolean tryLock(long time, TimeUnit unit) throws InterruptedException {
    if (Thread.interrupted())
        throw new InterruptedException();
    if (time <= 0)
        return tryLock();
    CacheOperationContext prev = gate.enter(opCtx);
    try {
        checkTx();
        IgniteInternalFuture<Boolean> fut = delegate.lockAllAsync(keys, unit.toMillis(time));
        try {
            boolean res = fut.get();
            if (res)
                incrementLockCounter();
            return res;
        } catch (IgniteInterruptedCheckedException e) {
            if (!fut.cancel()) {
                if (fut.isDone()) {
                    Boolean res = fut.get();
                    Thread.currentThread().interrupt();
                    if (res)
                        incrementLockCounter();
                    return res;
                }
            }
            if (e.getCause() instanceof InterruptedException)
                throw (InterruptedException) e.getCause();
            throw new InterruptedException();
        }
    } catch (IgniteCheckedException e) {
        throw new CacheException(e.getMessage(), e);
    } finally {
        gate.leave(prev);
    }
}
Also used : IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) CacheException(javax.cache.CacheException)

Aggregations

IgniteInterruptedCheckedException (org.apache.ignite.internal.IgniteInterruptedCheckedException)45 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)23 IOException (java.io.IOException)13 IgniteException (org.apache.ignite.IgniteException)10 IgniteSpiException (org.apache.ignite.spi.IgniteSpiException)10 ArrayList (java.util.ArrayList)8 File (java.io.File)5 CacheException (javax.cache.CacheException)5 List (java.util.List)4 UUID (java.util.UUID)4 ClusterNode (org.apache.ignite.cluster.ClusterNode)4 InetSocketAddress (java.net.InetSocketAddress)3 HashMap (java.util.HashMap)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 JobContextImpl (org.apache.hadoop.mapred.JobContextImpl)3 OutputFormat (org.apache.hadoop.mapreduce.OutputFormat)3 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)3 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)3 ServerSocket (java.net.ServerSocket)2