Search in sources :

Example 1 with RedisCachePremium

use of com.microsoft.azure.management.redis.RedisCachePremium in project azure-sdk-for-java by Azure.

the class Utils method print.

/**
     * Print Redis Cache.
     * @param redisCache a Redis cache.
     */
public static void print(RedisCache redisCache) {
    StringBuilder redisInfo = new StringBuilder().append("Redis Cache Name: ").append(redisCache.name()).append("\n\tResource group: ").append(redisCache.resourceGroupName()).append("\n\tRegion: ").append(redisCache.region()).append("\n\tSKU Name: ").append(redisCache.sku().name()).append("\n\tSKU Family: ").append(redisCache.sku().family()).append("\n\tHost name: ").append(redisCache.hostName()).append("\n\tSSL port: ").append(redisCache.sslPort()).append("\n\tNon-SSL port (6379) enabled: ").append(redisCache.nonSslPort());
    if (redisCache.redisConfiguration() != null && !redisCache.redisConfiguration().isEmpty()) {
        redisInfo.append("\n\tRedis Configuration:");
        for (Map.Entry<String, String> redisConfiguration : redisCache.redisConfiguration().entrySet()) {
            redisInfo.append("\n\t  '").append(redisConfiguration.getKey()).append("' : '").append(redisConfiguration.getValue()).append("'");
        }
    }
    if (redisCache.isPremium()) {
        RedisCachePremium premium = redisCache.asPremium();
        List<ScheduleEntry> scheduleEntries = premium.listPatchSchedules();
        if (scheduleEntries != null && !scheduleEntries.isEmpty()) {
            redisInfo.append("\n\tRedis Patch Schedule:");
            for (ScheduleEntry schedule : scheduleEntries) {
                redisInfo.append("\n\t\tDay: '").append(schedule.dayOfWeek()).append("', start at: '").append(schedule.startHourUtc()).append("', maintenance window: '").append(schedule.maintenanceWindow()).append("'");
            }
        }
    }
    System.out.println(redisInfo.toString());
}
Also used : ScheduleEntry(com.microsoft.azure.management.redis.ScheduleEntry) ConnectionString(com.microsoft.azure.management.appservice.ConnectionString) RedisCachePremium(com.microsoft.azure.management.redis.RedisCachePremium) Map(java.util.Map)

Example 2 with RedisCachePremium

use of com.microsoft.azure.management.redis.RedisCachePremium in project azure-sdk-for-java by Azure.

the class ManageRedisCache method runSample.

/**
     * Main function which runs the actual sample.
     * @param azure instance of the azure client
     * @return true if sample runs successfully
     */
public static boolean runSample(Azure azure) {
    final String redisCacheName1 = Utils.createRandomName("rc1");
    final String redisCacheName2 = Utils.createRandomName("rc2");
    final String redisCacheName3 = Utils.createRandomName("rc3");
    final String rgName = Utils.createRandomName("rgRCMC");
    try {
        // ============================================================
        // Define a redis cache
        System.out.println("Creating a Redis Cache");
        Creatable<RedisCache> redisCache1Definition = azure.redisCaches().define(redisCacheName1).withRegion(Region.US_CENTRAL).withNewResourceGroup(rgName).withBasicSku();
        // ============================================================
        // Define two more Redis caches
        Creatable<RedisCache> redisCache2Definition = azure.redisCaches().define(redisCacheName2).withRegion(Region.US_CENTRAL).withNewResourceGroup(rgName).withPremiumSku().withShardCount(3);
        Creatable<RedisCache> redisCache3Definition = azure.redisCaches().define(redisCacheName3).withRegion(Region.US_CENTRAL).withNewResourceGroup(rgName).withPremiumSku(2).withShardCount(3);
        // ============================================================
        // Create all the caches in parallel to save time
        System.out.println("Creating three Redis Caches in parallel... (this will take several minutes)");
        @SuppressWarnings("unchecked") CreatedResources<RedisCache> createdCaches = azure.redisCaches().create(redisCache1Definition, redisCache2Definition, redisCache3Definition);
        System.out.println("Created Redis caches:");
        RedisCache redisCache1 = createdCaches.get(redisCache1Definition.key());
        for (RedisCache redisCache : createdCaches.values()) {
            Utils.print(redisCache);
            System.out.println();
        }
        // ============================================================
        // Get | regenerate Redis Cache access keys
        System.out.println("Getting the first Redis cache's access keys");
        RedisAccessKeys redisAccessKeys = redisCache1.keys();
        Utils.print(redisAccessKeys);
        System.out.println("Regenerating secondary Redis cache access key");
        redisAccessKeys = redisCache1.regenerateKey(RedisKeyType.SECONDARY);
        Utils.print(redisAccessKeys);
        // ============================================================
        // List Redis Caches inside the resource group
        System.out.println("Listing Redis Caches");
        List<RedisCache> caches = azure.redisCaches().listByResourceGroup(rgName);
        // Walk through all the caches
        for (RedisCache redis : caches) {
            // If the instance of the Redis Cache is Premium Sku
            if (redis.isPremium()) {
                RedisCachePremium premium = redis.asPremium();
                // Update each Premium Sku Redis Cache instance
                System.out.println("Updating Premium Redis Cache");
                premium.update().withPatchSchedule(DayOfWeek.MONDAY, 5).withShardCount(4).withNonSslPort().withRedisConfiguration("maxmemory-policy", "allkeys-random").withRedisConfiguration("maxmemory-reserved", "20").apply();
                System.out.println("Updated Redis Cache:");
                Utils.print(premium);
                // Restart Redis Cache
                System.out.println("Restarting updated Redis Cache");
                premium.forceReboot(RebootType.ALL_NODES, 1);
                System.out.println("Redis Cache restart scheduled");
            }
        }
        // ============================================================
        // Delete a Redis Cache
        System.out.println("Deleting a Redis Cache  - " + redisCache1.name());
        azure.redisCaches().deleteById(redisCache1.id());
        System.out.println("Deleted Redis Cache");
        return true;
    } catch (Exception f) {
        System.out.println(f.getMessage());
        f.printStackTrace();
    } finally {
        if (azure.resourceGroups().getByName(rgName) != null) {
            System.out.println("Deleting Resource Group: " + rgName);
            azure.resourceGroups().deleteByName(rgName);
            System.out.println("Deleted Resource Group: " + rgName);
        } else {
            System.out.println("Did not create any resources in Azure. No clean up is necessary");
        }
    }
    return false;
}
Also used : RedisCache(com.microsoft.azure.management.redis.RedisCache) RedisCachePremium(com.microsoft.azure.management.redis.RedisCachePremium) RedisAccessKeys(com.microsoft.azure.management.redis.RedisAccessKeys)

Aggregations

RedisCachePremium (com.microsoft.azure.management.redis.RedisCachePremium)2 ConnectionString (com.microsoft.azure.management.appservice.ConnectionString)1 RedisAccessKeys (com.microsoft.azure.management.redis.RedisAccessKeys)1 RedisCache (com.microsoft.azure.management.redis.RedisCache)1 ScheduleEntry (com.microsoft.azure.management.redis.ScheduleEntry)1 Map (java.util.Map)1