use of com.microsoft.azure.management.redis.RedisCache in project azure-tools-for-java by Microsoft.
the class RedisCacheModule method refreshItems.
@Override
protected void refreshItems() throws AzureCmdException {
List<Pair<String, String>> failedSubscriptions = new ArrayList<>();
try {
AzureManager azureManager = AuthMethodManager.getInstance().getAzureManager();
// not signed in
if (azureManager == null) {
return;
}
SubscriptionManager subscriptionManager = azureManager.getSubscriptionManager();
Set<String> sidList = subscriptionManager.getAccountSidList();
for (String sid : sidList) {
try {
Azure azure = azureManager.getAzure(sid);
for (RedisCache cache : azure.redisCaches().list()) {
addChildNode(new RedisCacheNode(this, sid, cache));
}
} catch (Exception ex) {
failedSubscriptions.add(new ImmutablePair<>(sid, ex.getMessage()));
continue;
}
}
} catch (Exception ex) {
DefaultLoader.getUIHelper().logError("An error occurred when trying to load Redis Caches\n\n" + ex.getMessage(), ex);
}
if (!failedSubscriptions.isEmpty()) {
StringBuilder errorMessage = new StringBuilder("An error occurred when trying to load Redis Caches for the subscriptions:\n\n");
for (Pair error : failedSubscriptions) {
errorMessage.append(error.getKey()).append(": ").append(error.getValue()).append("\n");
}
DefaultLoader.getUIHelper().logError("An error occurred when trying to load Redis Caches\n\n" + errorMessage.toString(), null);
}
}
use of com.microsoft.azure.management.redis.RedisCache 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;
}
use of com.microsoft.azure.management.redis.RedisCache in project azure-tools-for-java by Microsoft.
the class CreateRedisCacheForm method doValidate.
@Nullable
@Override
protected ValidationInfo doValidate() {
redisCacheNameValue = txtRedisName.getText();
selectedResGrpValue = newResGrp ? txtNewResGrp.getText() : cbUseExist.getSelectedItem().toString();
selectedLocationValue = ((Location) cbLocations.getSelectedItem()).inner().name();
selectedPriceTierValue = cbPricing.getSelectedItem().toString();
if (redisCacheNameValue.length() > REDIS_CACHE_MAX_NAME_LENGTH || !redisCacheNameValue.matches(DNS_NAME_REGEX)) {
return new ValidationInfo(INVALID_REDIS_CACHE_NAME, txtRedisName);
}
try {
for (RedisCache existingRedisCache : azureManager.getAzure(currentSub.getSubscriptionId()).redisCaches().list()) {
if (existingRedisCache.name().equals(redisCacheNameValue)) {
return new ValidationInfo(String.format(VALIDATION_FORMAT, redisCacheNameValue), txtRedisName);
}
}
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
Aggregations