Search in sources :

Example 76 with HazelcastException

use of com.hazelcast.core.HazelcastException in project hazelcast by hazelcast.

the class PartitionStateManager method initializePartitionAssignments.

boolean initializePartitionAssignments(Set<Address> excludedAddresses) {
    if (!isPartitionAssignmentAllowed()) {
        return false;
    }
    Collection<MemberGroup> memberGroups = createMemberGroups(excludedAddresses);
    if (memberGroups.isEmpty()) {
        logger.warning("No member group is available to assign partition ownership...");
        return false;
    }
    logger.info("Initializing cluster partition table arrangement...");
    Address[][] newState = partitionStateGenerator.arrange(memberGroups, partitions);
    if (newState.length != partitionCount) {
        throw new HazelcastException("Invalid partition count! " + "Expected: " + partitionCount + ", Actual: " + newState.length);
    }
    // increment state version to make fail cluster state transaction
    // if it's started and not locked the state yet.
    stateVersion.incrementAndGet();
    ClusterState clusterState = node.getClusterService().getClusterState();
    if (clusterState != ClusterState.ACTIVE) {
        // cluster state is either changed or locked, decrement version back and fail.
        stateVersion.decrementAndGet();
        logger.warning("Partitions can't be assigned since cluster-state= " + clusterState);
        return false;
    }
    for (int partitionId = 0; partitionId < partitionCount; partitionId++) {
        InternalPartitionImpl partition = partitions[partitionId];
        Address[] replicas = newState[partitionId];
        partition.setReplicaAddresses(replicas);
    }
    setInitialized();
    return true;
}
Also used : MemberGroup(com.hazelcast.partition.membergroup.MemberGroup) ClusterState(com.hazelcast.cluster.ClusterState) HazelcastException(com.hazelcast.core.HazelcastException) Address(com.hazelcast.nio.Address)

Example 77 with HazelcastException

use of com.hazelcast.core.HazelcastException in project hazelcast by hazelcast.

the class IOUtil method copyFile.

/**
     * Copies source file to target and creates the target if necessary. The target can be a directory or file. If the target
     * is a file, nests the new file under the target directory, otherwise copies to the given target.
     *
     * @param source      the source file
     * @param target      the destination file or directory
     * @param sourceCount The maximum number of bytes to be transferred. If negative transfers the entire source file.
     * @throws IllegalArgumentException if the source was not found or the source not a file
     * @throws HazelcastException       if there was any exception while creating directories or copying
     */
public static void copyFile(File source, File target, long sourceCount) {
    if (!source.exists()) {
        throw new IllegalArgumentException("Source does not exist");
    }
    if (!source.isFile()) {
        throw new IllegalArgumentException("Source is not a file");
    }
    if (!target.exists() && !target.mkdirs()) {
        throw new HazelcastException("Could not create the target directory " + target);
    }
    final File destination = target.isDirectory() ? new File(target, source.getName()) : target;
    FileInputStream in = null;
    FileOutputStream out = null;
    try {
        in = new FileInputStream(source);
        out = new FileOutputStream(destination);
        final FileChannel inChannel = in.getChannel();
        final FileChannel outChannel = out.getChannel();
        final long transferCount = sourceCount > 0 ? sourceCount : inChannel.size();
        inChannel.transferTo(0, transferCount, outChannel);
    } catch (Exception e) {
        throw new HazelcastException("Error occurred while copying", e);
    } finally {
        closeResource(in);
        closeResource(out);
    }
}
Also used : HazelcastException(com.hazelcast.core.HazelcastException) FileChannel(java.nio.channels.FileChannel) FileOutputStream(java.io.FileOutputStream) File(java.io.File) FileInputStream(java.io.FileInputStream) DataFormatException(java.util.zip.DataFormatException) HazelcastException(com.hazelcast.core.HazelcastException) IOException(java.io.IOException) EOFException(java.io.EOFException)

Example 78 with HazelcastException

use of com.hazelcast.core.HazelcastException in project hazelcast by hazelcast.

the class IOUtilTest method testCopyFileFailsWhenTargetDoesntExistAndCannotBeCreated.

@Test
public void testCopyFileFailsWhenTargetDoesntExistAndCannotBeCreated() throws IOException {
    final File target = mock(File.class);
    when(target.exists()).thenReturn(false);
    when(target.mkdirs()).thenReturn(false);
    final File source = new File("source");
    assertTrue(!source.exists());
    source.createNewFile();
    try {
        copyFile(source, target, -1);
        fail();
    } catch (HazelcastException expected) {
        EmptyStatement.ignore(expected);
    }
    delete(source);
}
Also used : HazelcastException(com.hazelcast.core.HazelcastException) IOUtil.copyFile(com.hazelcast.nio.IOUtil.copyFile) File(java.io.File) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 79 with HazelcastException

use of com.hazelcast.core.HazelcastException in project hazelcast by hazelcast.

the class IOUtilTest method testCopyFailsWhenSourceCannotBeListed.

@Test
public void testCopyFailsWhenSourceCannotBeListed() throws IOException {
    final File source = mock(File.class);
    when(source.exists()).thenReturn(true);
    when(source.isDirectory()).thenReturn(true);
    when(source.listFiles()).thenReturn(null);
    when(source.getName()).thenReturn("dummy");
    final File dest = new File("dest");
    assertTrue(!dest.exists());
    dest.mkdir();
    try {
        copy(source, dest);
        fail();
    } catch (HazelcastException expected) {
        EmptyStatement.ignore(expected);
    }
    delete(dest);
}
Also used : HazelcastException(com.hazelcast.core.HazelcastException) IOUtil.copyFile(com.hazelcast.nio.IOUtil.copyFile) File(java.io.File) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 80 with HazelcastException

use of com.hazelcast.core.HazelcastException in project hazelcast by hazelcast.

the class ExceptionUtilTest method testPeel_whenThrowableIsExecutionExceptionWithNullCause_thenReturnHazelcastException.

@Test
public void testPeel_whenThrowableIsExecutionExceptionWithNullCause_thenReturnHazelcastException() {
    ExecutionException exception = new ExecutionException(null);
    RuntimeException result = ExceptionUtil.peel(exception);
    assertTrue(result instanceof HazelcastException);
    assertEquals(exception, result.getCause());
}
Also used : HazelcastException(com.hazelcast.core.HazelcastException) ExecutionException(java.util.concurrent.ExecutionException) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

HazelcastException (com.hazelcast.core.HazelcastException)123 IOException (java.io.IOException)43 QuickTest (com.hazelcast.test.annotation.QuickTest)19 Test (org.junit.Test)19 TxQueueItem (com.hazelcast.collection.impl.txnqueue.TxQueueItem)14 TransactionException (com.hazelcast.transaction.TransactionException)14 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)13 File (java.io.File)13 HazelcastInstanceNotActiveException (com.hazelcast.core.HazelcastInstanceNotActiveException)8 FileInputStream (java.io.FileInputStream)8 FileNotFoundException (java.io.FileNotFoundException)8 Data (com.hazelcast.internal.serialization.Data)7 OOfflineNodeException (com.orientechnologies.common.concur.OOfflineNodeException)6 Future (java.util.concurrent.Future)6 ONeedRetryException (com.orientechnologies.common.concur.ONeedRetryException)5 OException (com.orientechnologies.common.exception.OException)5 OIOException (com.orientechnologies.common.io.OIOException)5 ODistributedRedirectException (com.orientechnologies.orient.enterprise.channel.binary.ODistributedRedirectException)5 EOFException (java.io.EOFException)5 ArrayList (java.util.ArrayList)5