Search in sources :

Example 1 with CacheExistsException

use of org.apache.geode.cache.CacheExistsException in project geode by apache.

the class DiskStoreCommands method alterOfflineDiskStore.

@CliCommand(value = CliStrings.ALTER_DISK_STORE, help = CliStrings.ALTER_DISK_STORE__HELP)
@CliMetaData(shellOnly = true, relatedTopic = { CliStrings.TOPIC_GEODE_DISKSTORE })
public Result alterOfflineDiskStore(@CliOption(key = CliStrings.ALTER_DISK_STORE__DISKSTORENAME, mandatory = true, help = CliStrings.ALTER_DISK_STORE__DISKSTORENAME__HELP) String diskStoreName, @CliOption(key = CliStrings.ALTER_DISK_STORE__REGIONNAME, mandatory = true, help = CliStrings.ALTER_DISK_STORE__REGIONNAME__HELP) String regionName, @CliOption(key = CliStrings.ALTER_DISK_STORE__DISKDIRS, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.ALTER_DISK_STORE__DISKDIRS__HELP, mandatory = true) String[] diskDirs, @CliOption(key = CliStrings.ALTER_DISK_STORE__COMPRESSOR, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, specifiedDefaultValue = "none", help = CliStrings.ALTER_DISK_STORE__COMPRESSOR__HELP) String compressorClassName, @CliOption(key = CliStrings.ALTER_DISK_STORE__CONCURRENCY__LEVEL, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.ALTER_DISK_STORE__CONCURRENCY__LEVEL__HELP) Integer concurrencyLevel, @CliOption(key = CliStrings.ALTER_DISK_STORE__STATISTICS__ENABLED, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.ALTER_DISK_STORE__STATISTICS__ENABLED__HELP) Boolean statisticsEnabled, @CliOption(key = CliStrings.ALTER_DISK_STORE__INITIAL__CAPACITY, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.ALTER_DISK_STORE__INITIAL__CAPACITY__HELP) Integer initialCapacity, @CliOption(key = CliStrings.ALTER_DISK_STORE__LOAD__FACTOR, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.ALTER_DISK_STORE__LOAD__FACTOR__HELP) Float loadFactor, @CliOption(key = CliStrings.ALTER_DISK_STORE__LRU__EVICTION__ACTION, help = CliStrings.ALTER_DISK_STORE__LRU__EVICTION__ACTION__HELP) String lruEvictionAction, @CliOption(key = CliStrings.ALTER_DISK_STORE__LRU__EVICTION__ALGORITHM, help = CliStrings.ALTER_DISK_STORE__LRU__EVICTION__ALGORITHM__HELP) String lruEvictionAlgo, @CliOption(key = CliStrings.ALTER_DISK_STORE__LRU__EVICTION__LIMIT, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.ALTER_DISK_STORE__LRU__EVICTION__LIMIT__HELP) Integer lruEvictionLimit, @CliOption(key = CliStrings.ALTER_DISK_STORE__OFF_HEAP, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.ALTER_DISK_STORE__OFF_HEAP__HELP) Boolean offHeap, @CliOption(key = CliStrings.ALTER_DISK_STORE__REMOVE, help = CliStrings.ALTER_DISK_STORE__REMOVE__HELP, mandatory = false, specifiedDefaultValue = "true", unspecifiedDefaultValue = "false") boolean remove) {
    Result result = null;
    try {
        File[] dirs = null;
        if (diskDirs != null) {
            dirs = new File[diskDirs.length];
            for (int i = 0; i < diskDirs.length; i++) {
                dirs[i] = new File((diskDirs[i]));
            }
        }
        if (regionName.equals(Region.SEPARATOR)) {
            return ResultBuilder.createUserErrorResult(CliStrings.INVALID_REGION_NAME);
        }
        if ((lruEvictionAlgo != null) || (lruEvictionAction != null) || (lruEvictionLimit != null) || (concurrencyLevel != null) || (initialCapacity != null) || (loadFactor != null) || (compressorClassName != null) || (offHeap != null) || (statisticsEnabled != null)) {
            if (!remove) {
                String lruEvictionLimitString = lruEvictionLimit == null ? null : lruEvictionLimit.toString();
                String concurrencyLevelString = concurrencyLevel == null ? null : concurrencyLevel.toString();
                String initialCapacityString = initialCapacity == null ? null : initialCapacity.toString();
                String loadFactorString = loadFactor == null ? null : loadFactor.toString();
                String statisticsEnabledString = statisticsEnabled == null ? null : statisticsEnabled.toString();
                String offHeapString = offHeap == null ? null : offHeap.toString();
                if ("none".equals(compressorClassName)) {
                    compressorClassName = "";
                }
                String resultMessage = DiskStoreImpl.modifyRegion(diskStoreName, dirs, "/" + regionName, lruEvictionAlgo, lruEvictionAction, lruEvictionLimitString, concurrencyLevelString, initialCapacityString, loadFactorString, compressorClassName, statisticsEnabledString, offHeapString, false);
                result = ResultBuilder.createInfoResult(resultMessage);
            } else {
                result = ResultBuilder.createParsingErrorResult("Cannot use the --remove=true parameter with any other parameters");
            }
        } else {
            if (remove) {
                DiskStoreImpl.destroyRegion(diskStoreName, dirs, "/" + regionName);
                result = ResultBuilder.createInfoResult("The region " + regionName + " was successfully removed from the disk store " + diskStoreName);
            } else {
                // Please provide an option
                result = ResultBuilder.createParsingErrorResult("Please provide a relevant parameter");
            }
        }
    // Catch the IllegalArgumentException thrown by the modifyDiskStore function and sent the
    } catch (IllegalArgumentException e) {
        String message = "Please check the parameters";
        message += "\n" + e.getMessage();
        result = ResultBuilder.createGemFireErrorResult(message);
    } catch (IllegalStateException e) {
        result = ResultBuilder.createGemFireErrorResult(e.getMessage());
    } catch (CacheExistsException e) {
        // Indicates that the command is being used when a cache is open
        result = ResultBuilder.createGemFireErrorResult("Cannot execute " + CliStrings.ALTER_DISK_STORE + " when a cache exists (Offline command)");
    } catch (Exception e) {
        result = createErrorResult(e.getMessage());
    }
    return result;
}
Also used : CacheExistsException(org.apache.geode.cache.CacheExistsException) File(java.io.File) ConverterHint(org.apache.geode.management.cli.ConverterHint) CommandResultException(org.apache.geode.management.internal.cli.result.CommandResultException) CacheExistsException(org.apache.geode.cache.CacheExistsException) MemberNotFoundException(org.apache.geode.management.internal.cli.util.MemberNotFoundException) DiskStoreNotFoundException(org.apache.geode.management.internal.cli.util.DiskStoreNotFoundException) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) ResultDataException(org.apache.geode.management.internal.cli.result.ResultDataException) GemFireIOException(org.apache.geode.GemFireIOException) IOException(java.io.IOException) Result(org.apache.geode.management.cli.Result) CliFunctionResult(org.apache.geode.management.internal.cli.functions.CliFunctionResult) CliCommand(org.springframework.shell.core.annotation.CliCommand) CliMetaData(org.apache.geode.management.cli.CliMetaData)

Example 2 with CacheExistsException

use of org.apache.geode.cache.CacheExistsException in project geode by apache.

the class CacheJUnitTest method testScenario3.

/**
   * Test of testScenario3 method, of class org.apache.geode.internal.jta.functional.CacheTest1.
   * Tests whether a user transaction with cache lookup and with XAPooledDataSOurce supports Cache
   * put and get operations accordingly. Put and get are done within the transaction block and also
   * db updates are done. After committing we check whether commit is proper in db and also in
   * Cache.
   */
@Test
public void testScenario3() throws Exception {
    this.tblIDFld = 3;
    this.tblNameFld = "test3";
    boolean rollback_chances = true;
    final String DEFAULT_RGN = "root";
    JTAUtils jtaObj = new JTAUtils(cache, currRegion);
    jtaObj.deleteRows(this.tblName);
    Context ctx = cache.getJNDIContext();
    UserTransaction ta = (UserTransaction) ctx.lookup("java:/UserTransaction");
    Connection conn = null;
    try {
        /** begin the transaction **/
        ta.begin();
        String current_region = jtaObj.currRegion.getName();
        assertEquals("the default region is not root", DEFAULT_RGN, current_region);
        jtaObj.getRegionFromCache("region1");
        String current_fullpath = jtaObj.currRegion.getFullPath();
        assertEquals("failed retrieving current region fullpath", "/" + DEFAULT_RGN + "/region1", current_fullpath);
        jtaObj.put("key1", "value1");
        String str = jtaObj.get("key1");
        String tok = jtaObj.parseGetValue(str);
        assertEquals("get failed for corresponding put", "\"value1\"", tok);
        current_fullpath = jtaObj.currRegion.getFullPath();
        assertEquals("failed retrieving current region fullpath", "/" + DEFAULT_RGN + "/region1", current_fullpath);
        DataSource da = (DataSource) ctx.lookup("java:/XAPooledDataSource");
        conn = da.getConnection();
        Statement stmt = conn.createStatement();
        String sqlSTR = "insert into " + this.tblName + " values (" + this.tblIDFld + "," + "'" + this.tblNameFld + "'" + ")";
        stmt.executeUpdate(sqlSTR);
        stmt.close();
        ta.commit();
        conn.close();
        rollback_chances = false;
        current_fullpath = jtaObj.currRegion.getFullPath();
        assertEquals("failed retrieving current region fullpath after txn commit", "/" + DEFAULT_RGN + "/region1", current_fullpath);
        int ifAnyRows = jtaObj.getRows(this.tblName);
        assertEquals("rows retrieved is:" + ifAnyRows, 1, ifAnyRows);
        /*
       * if (ifAnyRows == 0) { fail (" DB FAILURE: no rows retrieved even after txn commit."); }
       */
        // after jdbc commit cache value in region1 for key1 must retain...
        str = jtaObj.get("key1");
        tok = jtaObj.parseGetValue(str);
        assertEquals("cache put didn't commit, value retrieved is: " + tok, "\"value1\"", tok);
    } catch (CacheExistsException e) {
        ta.rollback();
        fail(" test 3 failed ");
    } catch (NamingException e) {
        if (rollback_chances)
            ta.rollback();
        fail(" test 3 failed " + e.getMessage());
    } catch (SQLException e) {
        if (rollback_chances)
            ta.rollback();
        fail(" test 3 failed " + e.getMessage());
    } catch (Exception e) {
        if (rollback_chances)
            ta.rollback();
        fail(" test 3 failed " + e.getMessage());
    } finally {
        if (conn != null)
            try {
                conn.close();
            } catch (SQLException e) {
            }
    }
}
Also used : Context(javax.naming.Context) UserTransaction(javax.transaction.UserTransaction) SQLException(java.sql.SQLException) Statement(java.sql.Statement) Connection(java.sql.Connection) JTAUtils(org.apache.geode.internal.jta.JTAUtils) NamingException(javax.naming.NamingException) SQLException(java.sql.SQLException) CacheLoaderException(org.apache.geode.cache.CacheLoaderException) CacheExistsException(org.apache.geode.cache.CacheExistsException) CacheException(org.apache.geode.cache.CacheException) DataSource(javax.sql.DataSource) CacheExistsException(org.apache.geode.cache.CacheExistsException) NamingException(javax.naming.NamingException) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 3 with CacheExistsException

use of org.apache.geode.cache.CacheExistsException in project geode by apache.

the class CacheJUnitTest method testScenario4.

/**
   * Test of testScenario4 method, of class org.apache.geode.internal.jta.functional.CacheTest1.
   * Tests whether a user transaction with cache lookup and with XAPooledDataSOurce supports Cache
   * put and get operations accordingly along with JTA behavior. Put and get are done within the
   * transaction block and also db updates are done. After rollback the transaction explicitly we
   * check whether it was proper in db and also in Cache, which should also rollback.
   */
@Test
public void testScenario4() throws Exception {
    this.tblIDFld = 4;
    this.tblNameFld = "test4";
    boolean rollback_chances = true;
    final String DEFAULT_RGN = "root";
    JTAUtils jtaObj = new JTAUtils(cache, currRegion);
    jtaObj.deleteRows(this.tblName);
    Context ctx = cache.getJNDIContext();
    UserTransaction ta = (UserTransaction) ctx.lookup("java:/UserTransaction");
    Connection conn = null;
    try {
        String current_region = jtaObj.currRegion.getName();
        assertEquals("default region is not root", DEFAULT_RGN, current_region);
        jtaObj.getRegionFromCache("region1");
        String current_fullpath = jtaObj.currRegion.getFullPath();
        assertEquals("failed retrieving current region fullpath after doing getRegionFromCache(region1)", "/" + DEFAULT_RGN + "/region1", current_fullpath);
        jtaObj.put("key1", "test");
        ta.begin();
        jtaObj.put("key1", "value1");
        String str = jtaObj.get("key1");
        String tok = jtaObj.parseGetValue(str);
        assertEquals("get value do not match with the put", "\"value1\"", tok);
        current_fullpath = jtaObj.currRegion.getFullPath();
        assertEquals("failed retrieving current region fullpath", "/" + DEFAULT_RGN + "/region1", current_fullpath);
        DataSource da = (DataSource) ctx.lookup("java:/XAPooledDataSource");
        conn = da.getConnection();
        Statement stmt = conn.createStatement();
        String sqlSTR = "insert into " + this.tblName + " values (" + this.tblIDFld + "," + "'" + this.tblNameFld + "'" + ")";
        stmt.executeUpdate(sqlSTR);
        stmt.close();
        ta.rollback();
        conn.close();
        rollback_chances = false;
        current_fullpath = jtaObj.currRegion.getFullPath();
        assertEquals("failed retirieving current region fullpath after txn rollback", "/" + DEFAULT_RGN + "/region1", current_fullpath);
        int ifAnyRows = jtaObj.getRows(this.tblName);
        assertEquals("rows retrieved is: " + ifAnyRows, 0, ifAnyRows);
        /*
       * if (ifAnyRows != 0) { fail (" DB FAILURE"); }
       */
        str = jtaObj.get("key1");
        tok = jtaObj.parseGetValue(str);
        assertEquals("value existing in cache is: " + tok, "\"test\"", tok);
    } catch (CacheExistsException e) {
        ta.rollback();
        fail(" failed " + e.getMessage());
    } catch (NamingException e) {
        if (rollback_chances)
            ta.rollback();
        fail(" failed " + e.getMessage());
    } catch (SQLException e) {
        if (rollback_chances)
            ta.rollback();
        fail(" failed " + e.getMessage());
    } catch (Exception e) {
        if (rollback_chances)
            ta.rollback();
        fail(" failed " + e.getMessage());
    } finally {
        if (conn != null)
            try {
                conn.close();
            } catch (SQLException e) {
            }
    }
}
Also used : Context(javax.naming.Context) UserTransaction(javax.transaction.UserTransaction) SQLException(java.sql.SQLException) Statement(java.sql.Statement) Connection(java.sql.Connection) JTAUtils(org.apache.geode.internal.jta.JTAUtils) NamingException(javax.naming.NamingException) SQLException(java.sql.SQLException) CacheLoaderException(org.apache.geode.cache.CacheLoaderException) CacheExistsException(org.apache.geode.cache.CacheExistsException) CacheException(org.apache.geode.cache.CacheException) DataSource(javax.sql.DataSource) CacheExistsException(org.apache.geode.cache.CacheExistsException) NamingException(javax.naming.NamingException) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 4 with CacheExistsException

use of org.apache.geode.cache.CacheExistsException in project geode by apache.

the class CacheJUnitTest method testScenario7.

/**
   * Test of testScenario7 method, of class org.apache.geode.internal.jta.functional.CacheTest1.
   * Tests a user transaction with cache lookup and with XAPooledDataSource lookup. It does get and
   * put operations on the cache within the transaction block and checks whether these operations
   * are committed once the transaction is committed.
   */
@Test
public void testScenario7() throws Exception {
    this.tblIDFld = 7;
    this.tblNameFld = "test7";
    boolean rollback_chances = true;
    final String DEFAULT_RGN = "root";
    JTAUtils jtaObj = new JTAUtils(cache, currRegion);
    jtaObj.deleteRows(this.tblName);
    Context ctx = cache.getJNDIContext();
    UserTransaction ta = (UserTransaction) ctx.lookup("java:/UserTransaction");
    Connection conn = null;
    try {
        ta.begin();
        String current_region = jtaObj.currRegion.getName();
        assertEquals("default region is not root", DEFAULT_RGN, current_region);
        jtaObj.getRegionFromCache("region1");
        // now current region should point to region1, as done from within
        // getRegionFromCache method...
        String current_fullpath = jtaObj.currRegion.getFullPath();
        assertEquals("failed retrieving the current region fullpath", "/" + DEFAULT_RGN + "/region1", current_fullpath);
        jtaObj.put("key1", "value1");
        // try to get value1 from key1 in the same region
        String str = jtaObj.get("key1");
        String tok = jtaObj.parseGetValue(str);
        assertEquals("get value mismatch with put", "\"value1\"", tok);
        current_fullpath = jtaObj.currRegion.getFullPath();
        assertEquals("failed retrieving current region fullpath", "/" + DEFAULT_RGN + "/region1", current_fullpath);
        DataSource da = (DataSource) ctx.lookup("java:/XAPooledDataSource");
        conn = da.getConnection();
        ta.commit();
        conn.close();
        rollback_chances = false;
        current_fullpath = jtaObj.currRegion.getFullPath();
        assertEquals("failed retrieving current region fullpath after txn commit, fullpath is: " + current_region, "/" + DEFAULT_RGN + "/region1", current_fullpath);
        str = jtaObj.get("key1");
        tok = jtaObj.parseGetValue(str);
        assertEquals("cache value found is: " + tok, "\"value1\"", tok);
    } catch (CacheExistsException e) {
        if (rollback_chances)
            ta.rollback();
        fail(" failed due to: " + e.getMessage());
    } catch (NamingException e) {
        ta.rollback();
        fail(" failed due to: " + e.getMessage());
    } catch (SQLException e) {
        ta.rollback();
        fail(" failed due to: " + e.getMessage());
    } catch (Exception e) {
        if (rollback_chances)
            ta.rollback();
        fail(" failed due to: " + e.getMessage());
    } finally {
        if (conn != null)
            try {
                conn.close();
            } catch (Exception e) {
            }
    }
}
Also used : Context(javax.naming.Context) UserTransaction(javax.transaction.UserTransaction) SQLException(java.sql.SQLException) Connection(java.sql.Connection) CacheExistsException(org.apache.geode.cache.CacheExistsException) NamingException(javax.naming.NamingException) JTAUtils(org.apache.geode.internal.jta.JTAUtils) NamingException(javax.naming.NamingException) SQLException(java.sql.SQLException) CacheLoaderException(org.apache.geode.cache.CacheLoaderException) CacheExistsException(org.apache.geode.cache.CacheExistsException) CacheException(org.apache.geode.cache.CacheException) DataSource(javax.sql.DataSource) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 5 with CacheExistsException

use of org.apache.geode.cache.CacheExistsException in project geode by apache.

the class PartitionedRegionBucketCreationDistributionDUnitTest method createLonerCacheWithEnforceUniqueHost.

/**
   * Creates the <code>Cache</code> for this test that is not connected to other members.
   *
   * <p>
   * Used by test {@link #testEnforceUniqueHostForLonerDistributedSystem()}. Moved from
   * DistributedTestCase to this test is the exclusive caller.
   *
   * <p>
   * Added specifically to test scenario of defect #47181.
   */
private Cache createLonerCacheWithEnforceUniqueHost() {
    Cache myCache = null;
    try {
        System.setProperty(DistributionConfig.GEMFIRE_PREFIX + "DISABLE_DISCONNECT_DS_ON_CACHE_CLOSE", "true");
        myCache = CacheFactory.create(getLonerSystemWithEnforceUniqueHost());
    } catch (CacheExistsException e) {
        Assert.fail("the cache already exists", e);
    } catch (RuntimeException ex) {
        throw ex;
    } catch (Exception ex) {
        Assert.fail("Checked exception while initializing cache??", ex);
    } finally {
        System.clearProperty(DistributionConfig.GEMFIRE_PREFIX + "DISABLE_DISCONNECT_DS_ON_CACHE_CLOSE");
    }
    return myCache;
}
Also used : CacheExistsException(org.apache.geode.cache.CacheExistsException) PartitionedRegionStorageException(org.apache.geode.cache.PartitionedRegionStorageException) NoSuchElementException(java.util.NoSuchElementException) CacheExistsException(org.apache.geode.cache.CacheExistsException) CacheException(org.apache.geode.cache.CacheException) Cache(org.apache.geode.cache.Cache)

Aggregations

CacheExistsException (org.apache.geode.cache.CacheExistsException)11 CacheException (org.apache.geode.cache.CacheException)9 Connection (java.sql.Connection)4 SQLException (java.sql.SQLException)4 Context (javax.naming.Context)4 NamingException (javax.naming.NamingException)4 DataSource (javax.sql.DataSource)4 UserTransaction (javax.transaction.UserTransaction)4 Cache (org.apache.geode.cache.Cache)4 CacheLoaderException (org.apache.geode.cache.CacheLoaderException)4 JTAUtils (org.apache.geode.internal.jta.JTAUtils)4 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)4 Test (org.junit.Test)4 IOException (java.io.IOException)3 Statement (java.sql.Statement)3 RegionExistsException (org.apache.geode.cache.RegionExistsException)2 TimeoutException (org.apache.geode.cache.TimeoutException)2 InternalCache (org.apache.geode.internal.cache.InternalCache)2 IgnoredException (org.apache.geode.test.dunit.IgnoredException)2 File (java.io.File)1