Skip to content

Commit

Permalink
ISPN-2492 Rename the XSiteAdminOperations.status(String) method to si…
Browse files Browse the repository at this point in the history
…teStatus(String) to avoid overloading which

breaks RHQ
Add additional checks in the RHQ plugin metadata generation to avoid accidental duplicates
  • Loading branch information
tristantarrant committed Nov 13, 2012
1 parent 9c8c54b commit 3eec564
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 13 deletions.
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ public Collection<String> getCacheLoaders() {
} }
} }
@ManagedOperation(description = "Disable all cache loaders of a given type, where type is a fully qualified class name of the cache loader to disable") @ManagedOperation(description = "Disable all cache loaders of a given type, where type is a fully qualified class name of the cache loader to disable")
@Operation(displayName = "Disable all cache loaders of a given type, where type is a fully qualified class name of the cache loader to disable") @Operation(displayName = "Disable all cache loaders of a given type")
/** /**
* Disables a cache loader of a given type, where type is the fully qualified class name of a {@link CacheLoader} implementation. * Disables a cache loader of a given type, where type is the fully qualified class name of a {@link CacheLoader} implementation.
* *
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
public class RollingUpgradeManager { public class RollingUpgradeManager {
private final ConcurrentMap<String, Migrator> migrators = new ConcurrentHashMap<String, Migrator>(2); private final ConcurrentMap<String, Migrator> migrators = new ConcurrentHashMap<String, Migrator>(2);
@ManagedOperation(description = "Dumps the global known keyset to a well-known key for retrieval by the upgrade process") @ManagedOperation(description = "Dumps the global known keyset to a well-known key for retrieval by the upgrade process")
@Operation(displayName = "Dumps the global known keyset to a well-known key for retrieval by the upgrade process") @Operation(displayName = "Dumps the global known keyset")
public void recordKnownGlobalKeyset() { public void recordKnownGlobalKeyset() {
for (Migrator m: migrators.values()) m.recordKnownGlobalKeyset(); for (Migrator m: migrators.values()) m.recordKnownGlobalKeyset();
} }
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void init(RpcManager rpcManager, BackupSender backupSender, Cache cache)


@Operation(displayName = "Check whether the given backup site is offline or not.") @Operation(displayName = "Check whether the given backup site is offline or not.")
@ManagedOperation(description = "Check whether the given backup site is offline or not.") @ManagedOperation(description = "Check whether the given backup site is offline or not.")
public String status(String site) { public String siteStatus(String site) {
//also consider local node //also consider local node
OfflineStatus offlineStatus = backupSender.getOfflineStatus(site); OfflineStatus offlineStatus = backupSender.getOfflineStatus(site);
if (offlineStatus == null) if (offlineStatus == null)
Expand Down Expand Up @@ -185,13 +185,13 @@ public String takeSiteOffline(String site) {
return returnFailureOrSuccess(failed, prefix); return returnFailureOrSuccess(failed, prefix);
} }


@Operation(displayName = "Amends the values for 'afterFailures' for the 'TakeOffline' functionality on all the nodes in the cluster.") @Operation(displayName = "Amends the values for 'TakeOffline.afterFailures' on all the nodes in the cluster.")
@ManagedOperation(description = "Amends the values for 'afterFailures' for the 'TakeOffline' functionality on all the nodes in the cluster.") @ManagedOperation(description = "Amends the values for 'afterFailures' for the 'TakeOffline' functionality on all the nodes in the cluster.")
public String setTakeOfflineAfterFailures(String site, int afterFailures) { public String setTakeOfflineAfterFailures(String site, int afterFailures) {
return takeOffline(site, afterFailures, null); return takeOffline(site, afterFailures, null);
} }


@Operation(displayName = "Amends the values for 'minTimeToWait' for the 'TakeOffline' functionality on all the nodes in the cluster.") @Operation(displayName = "Amends the values for 'TakeOffline.minTimeToWait' on all the nodes in the cluster.")
@ManagedOperation(description = "Amends the values for 'minTimeToWait' for the 'TakeOffline' functionality on all the nodes in the cluster.") @ManagedOperation(description = "Amends the values for 'minTimeToWait' for the 'TakeOffline' functionality on all the nodes in the cluster.")
public String setTakeOfflineMinTimeToWait(String site, long minTimeToWait) { public String setTakeOfflineMinTimeToWait(String site, long minTimeToWait) {
return takeOffline(site, null, minTimeToWait); return takeOffline(site, null, minTimeToWait);
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -48,22 +48,22 @@ protected ConfigurationBuilder getLonActiveConfig() {
} }


public void testSiteStatus() { public void testSiteStatus() {
assertEquals(admin("LON", 0).status("NYC"), XSiteAdminOperations.ONLINE); assertEquals(admin("LON", 0).siteStatus("NYC"), XSiteAdminOperations.ONLINE);
assertEquals(admin("LON", 1).status("NYC"), XSiteAdminOperations.ONLINE); assertEquals(admin("LON", 1).siteStatus("NYC"), XSiteAdminOperations.ONLINE);


assertEquals(XSiteAdminOperations.SUCCESS, admin("LON", 1).takeSiteOffline("NYC")); assertEquals(XSiteAdminOperations.SUCCESS, admin("LON", 1).takeSiteOffline("NYC"));


assertEquals(admin("LON", 0).status("NYC"), XSiteAdminOperations.OFFLINE); assertEquals(admin("LON", 0).siteStatus("NYC"), XSiteAdminOperations.OFFLINE);
assertEquals(admin("LON", 1).status("NYC"), XSiteAdminOperations.OFFLINE); assertEquals(admin("LON", 1).siteStatus("NYC"), XSiteAdminOperations.OFFLINE);


assertEquals(XSiteAdminOperations.SUCCESS, admin("LON", 1).bringSiteOnline("NYC")); assertEquals(XSiteAdminOperations.SUCCESS, admin("LON", 1).bringSiteOnline("NYC"));
assertEquals(admin("LON", 0).status("NYC"), XSiteAdminOperations.ONLINE); assertEquals(admin("LON", 0).siteStatus("NYC"), XSiteAdminOperations.ONLINE);
assertEquals(admin("LON", 1).status("NYC"), XSiteAdminOperations.ONLINE); assertEquals(admin("LON", 1).siteStatus("NYC"), XSiteAdminOperations.ONLINE);
} }


public void amendTakeOffline() { public void amendTakeOffline() {
assertEquals(admin("LON", 0).status("NYC"), XSiteAdminOperations.ONLINE); assertEquals(admin("LON", 0).siteStatus("NYC"), XSiteAdminOperations.ONLINE);
assertEquals(admin("LON", 1).status("NYC"), XSiteAdminOperations.ONLINE); assertEquals(admin("LON", 1).siteStatus("NYC"), XSiteAdminOperations.ONLINE);


BackupSenderImpl bs = backupSender("LON", 0); BackupSenderImpl bs = backupSender("LON", 0);
OfflineStatus offlineStatus = bs.getOfflineStatus("NYC"); OfflineStatus offlineStatus = bs.getOfflineStatus("NYC");
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ private static void populateMetricsAndOperations(List<Class<?>> classes,
Props props, boolean withNamePrefix) throws Exception { Props props, boolean withNamePrefix) throws Exception {
props.setHasOperations(true); props.setHasOperations(true);
props.setHasMetrics(true); props.setHasMetrics(true);
Set<String> uniqueOperations = new HashSet<String>();
for (Class<?> clazz : classes) { for (Class<?> clazz : classes) {
MBean mbean = clazz.getAnnotation(MBean.class); MBean mbean = clazz.getAnnotation(MBean.class);
String prefix = withNamePrefix ? mbean.objectName() + '.' : ""; String prefix = withNamePrefix ? mbean.objectName() + '.' : "";
Expand All @@ -207,6 +208,7 @@ private static void populateMetricsAndOperations(List<Class<?>> classes,
} }
MetricProps metric = new MetricProps(property); MetricProps metric = new MetricProps(property);
String displayName = withNamePrefix ? "[" + mbean.objectName() + "] " + rhqMetric.displayName() : rhqMetric.displayName(); String displayName = withNamePrefix ? "[" + mbean.objectName() + "] " + rhqMetric.displayName() : rhqMetric.displayName();
validateDisplayName(displayName);
metric.setDisplayName(displayName); metric.setDisplayName(displayName);
metric.setDisplayType(rhqMetric.displayType()); metric.setDisplayType(rhqMetric.displayType());
metric.setDataType(rhqMetric.dataType()); metric.setDataType(rhqMetric.dataType());
Expand All @@ -233,8 +235,13 @@ private static void populateMetricsAndOperations(List<Class<?>> classes,
} else { } else {
name = prefix + ctMethod.getName(); name = prefix + ctMethod.getName();
} }
if (uniqueOperations.contains(name)) {
throw new RuntimeException("Duplicate operation name: "+name);
}
uniqueOperations.add(name);
OperationProps operation = new OperationProps(name); OperationProps operation = new OperationProps(name);
String displayName = withNamePrefix ? "[" + mbean.objectName() + "] " + rhqOperation.displayName() : rhqOperation.displayName(); String displayName = withNamePrefix ? "[" + mbean.objectName() + "] " + rhqOperation.displayName() : rhqOperation.displayName();
validateDisplayName(displayName);
operation.setDisplayName(displayName); operation.setDisplayName(displayName);
if (managedAttr != null) { if (managedAttr != null) {
debug("Operation has ManagedAttribute annotation " + managedAttr); debug("Operation has ManagedAttribute annotation " + managedAttr);
Expand Down Expand Up @@ -291,6 +298,7 @@ private static void populateMetricsAndOperations(List<Class<?>> classes,
} }
MetricProps metric = new MetricProps(property); MetricProps metric = new MetricProps(property);
String displayName = withNamePrefix ? "[" + mbean.objectName() + "] " + rhqMetric.displayName() : rhqMetric.displayName(); String displayName = withNamePrefix ? "[" + mbean.objectName() + "] " + rhqMetric.displayName() : rhqMetric.displayName();
validateDisplayName(displayName);
metric.setDisplayName(displayName); metric.setDisplayName(displayName);
metric.setDisplayType(rhqMetric.displayType()); metric.setDisplayType(rhqMetric.displayType());
metric.setDataType(rhqMetric.dataType()); metric.setDataType(rhqMetric.dataType());
Expand All @@ -311,6 +319,12 @@ private static void populateMetricsAndOperations(List<Class<?>> classes,
} }
} }


private static void validateDisplayName(String displayName) {
if (displayName.length() > 100) {
throw new RuntimeException("Display name too long (max 100 chars): "+displayName);
}
}

private static String getPropertyFromBeanConvention(CtMethod ctMethod) { private static String getPropertyFromBeanConvention(CtMethod ctMethod) {
String getterOrSetter = ctMethod.getName(); String getterOrSetter = ctMethod.getName();
if (getterOrSetter.startsWith("get") || getterOrSetter.startsWith("set")) { if (getterOrSetter.startsWith("get") || getterOrSetter.startsWith("set")) {
Expand Down

0 comments on commit 3eec564

Please sign in to comment.