@Test public void shouldUpgradeMultiAgentPermissions() throws Exception { Set<String> permissions = ImmutableSet.of("agent:abc,mno,xyz:view"); permissions = SchemaUpgrade.upgradePermissions(permissions); assertThat(Ordering.natural().sortedCopy(permissions)).containsExactly( "agent:abc,mno,xyz:error", "agent:abc,mno,xyz:jvm:environment", "agent:abc,mno,xyz:jvm:gauges", "agent:abc,mno,xyz:transaction"); }
@VisibleForTesting static @Nullable Set<String> upgradePermissions(Set<String> permissions) { Set<String> updatedPermissions = new HashSet<>(); ListMultimap<String, String> agentPermissions = ArrayListMultimap.create(); boolean needsUpgrade = false; for (String permission : permissions) { if (permission.startsWith("agent:")) { PermissionParser parser = new PermissionParser(permission); parser.parse(); String perm = parser.getPermission(); agentPermissions.put( PermissionParser.quoteIfNeededAndJoin(parser.getAgentRollupIds()), perm); if (perm.equals("agent:view")) { needsUpgrade = true; } } else if (permission.equals("admin") || permission.startsWith("admin:")) { updatedPermissions.add(permission); } else { logger.error("unexpected permission: {}", permission); } } if (!needsUpgrade) { return null; } for (Map.Entry<String, List<String>> entry : Multimaps.asMap(agentPermissions).entrySet()) { List<String> perms = entry.getValue(); PermissionParser.upgradeAgentPermissionsFrom_0_9_1_to_0_9_2(perms); for (String perm : perms) { updatedPermissions .add("agent:" + entry.getKey() + ":" + perm.substring("agent:".length())); } } if (updatedPermissions.contains("admin:view") && updatedPermissions.contains("admin:edit")) { updatedPermissions.remove("admin:view"); updatedPermissions.remove("admin:edit"); updatedPermissions.add("admin"); } return updatedPermissions; }
SchemaUpgrade { @VisibleForTesting static @Nullable Set<String> upgradePermissions(Set<String> permissions) { Set<String> updatedPermissions = new HashSet<>(); ListMultimap<String, String> agentPermissions = ArrayListMultimap.create(); boolean needsUpgrade = false; for (String permission : permissions) { if (permission.startsWith("agent:")) { PermissionParser parser = new PermissionParser(permission); parser.parse(); String perm = parser.getPermission(); agentPermissions.put( PermissionParser.quoteIfNeededAndJoin(parser.getAgentRollupIds()), perm); if (perm.equals("agent:view")) { needsUpgrade = true; } } else if (permission.equals("admin") || permission.startsWith("admin:")) { updatedPermissions.add(permission); } else { logger.error("unexpected permission: {}", permission); } } if (!needsUpgrade) { return null; } for (Map.Entry<String, List<String>> entry : Multimaps.asMap(agentPermissions).entrySet()) { List<String> perms = entry.getValue(); PermissionParser.upgradeAgentPermissionsFrom_0_9_1_to_0_9_2(perms); for (String perm : perms) { updatedPermissions .add("agent:" + entry.getKey() + ":" + perm.substring("agent:".length())); } } if (updatedPermissions.contains("admin:view") && updatedPermissions.contains("admin:edit")) { updatedPermissions.remove("admin:view"); updatedPermissions.remove("admin:edit"); updatedPermissions.add("admin"); } return updatedPermissions; } }
SchemaUpgrade { @VisibleForTesting static @Nullable Set<String> upgradePermissions(Set<String> permissions) { Set<String> updatedPermissions = new HashSet<>(); ListMultimap<String, String> agentPermissions = ArrayListMultimap.create(); boolean needsUpgrade = false; for (String permission : permissions) { if (permission.startsWith("agent:")) { PermissionParser parser = new PermissionParser(permission); parser.parse(); String perm = parser.getPermission(); agentPermissions.put( PermissionParser.quoteIfNeededAndJoin(parser.getAgentRollupIds()), perm); if (perm.equals("agent:view")) { needsUpgrade = true; } } else if (permission.equals("admin") || permission.startsWith("admin:")) { updatedPermissions.add(permission); } else { logger.error("unexpected permission: {}", permission); } } if (!needsUpgrade) { return null; } for (Map.Entry<String, List<String>> entry : Multimaps.asMap(agentPermissions).entrySet()) { List<String> perms = entry.getValue(); PermissionParser.upgradeAgentPermissionsFrom_0_9_1_to_0_9_2(perms); for (String perm : perms) { updatedPermissions .add("agent:" + entry.getKey() + ":" + perm.substring("agent:".length())); } } if (updatedPermissions.contains("admin:view") && updatedPermissions.contains("admin:edit")) { updatedPermissions.remove("admin:view"); updatedPermissions.remove("admin:edit"); updatedPermissions.add("admin"); } return updatedPermissions; } SchemaUpgrade(Session session, Clock clock, boolean servlet); }
SchemaUpgrade { @VisibleForTesting static @Nullable Set<String> upgradePermissions(Set<String> permissions) { Set<String> updatedPermissions = new HashSet<>(); ListMultimap<String, String> agentPermissions = ArrayListMultimap.create(); boolean needsUpgrade = false; for (String permission : permissions) { if (permission.startsWith("agent:")) { PermissionParser parser = new PermissionParser(permission); parser.parse(); String perm = parser.getPermission(); agentPermissions.put( PermissionParser.quoteIfNeededAndJoin(parser.getAgentRollupIds()), perm); if (perm.equals("agent:view")) { needsUpgrade = true; } } else if (permission.equals("admin") || permission.startsWith("admin:")) { updatedPermissions.add(permission); } else { logger.error("unexpected permission: {}", permission); } } if (!needsUpgrade) { return null; } for (Map.Entry<String, List<String>> entry : Multimaps.asMap(agentPermissions).entrySet()) { List<String> perms = entry.getValue(); PermissionParser.upgradeAgentPermissionsFrom_0_9_1_to_0_9_2(perms); for (String perm : perms) { updatedPermissions .add("agent:" + entry.getKey() + ":" + perm.substring("agent:".length())); } } if (updatedPermissions.contains("admin:view") && updatedPermissions.contains("admin:edit")) { updatedPermissions.remove("admin:view"); updatedPermissions.remove("admin:edit"); updatedPermissions.add("admin"); } return updatedPermissions; } SchemaUpgrade(Session session, Clock clock, boolean servlet); @Nullable Integer getInitialSchemaVersion(); void upgrade(); boolean reloadCentralConfiguration(); void updateSchemaVersionToCurent(); int getCurrentSchemaVersion(); void updateToMoreRecentCassandraOptions(CentralStorageConfig storageConfig); static AgentConfig upgradeOldAgentConfig(AgentConfig oldAgentConfig); }
SchemaUpgrade { @VisibleForTesting static @Nullable Set<String> upgradePermissions(Set<String> permissions) { Set<String> updatedPermissions = new HashSet<>(); ListMultimap<String, String> agentPermissions = ArrayListMultimap.create(); boolean needsUpgrade = false; for (String permission : permissions) { if (permission.startsWith("agent:")) { PermissionParser parser = new PermissionParser(permission); parser.parse(); String perm = parser.getPermission(); agentPermissions.put( PermissionParser.quoteIfNeededAndJoin(parser.getAgentRollupIds()), perm); if (perm.equals("agent:view")) { needsUpgrade = true; } } else if (permission.equals("admin") || permission.startsWith("admin:")) { updatedPermissions.add(permission); } else { logger.error("unexpected permission: {}", permission); } } if (!needsUpgrade) { return null; } for (Map.Entry<String, List<String>> entry : Multimaps.asMap(agentPermissions).entrySet()) { List<String> perms = entry.getValue(); PermissionParser.upgradeAgentPermissionsFrom_0_9_1_to_0_9_2(perms); for (String perm : perms) { updatedPermissions .add("agent:" + entry.getKey() + ":" + perm.substring("agent:".length())); } } if (updatedPermissions.contains("admin:view") && updatedPermissions.contains("admin:edit")) { updatedPermissions.remove("admin:view"); updatedPermissions.remove("admin:edit"); updatedPermissions.add("admin"); } return updatedPermissions; } SchemaUpgrade(Session session, Clock clock, boolean servlet); @Nullable Integer getInitialSchemaVersion(); void upgrade(); boolean reloadCentralConfiguration(); void updateSchemaVersionToCurent(); int getCurrentSchemaVersion(); void updateToMoreRecentCassandraOptions(CentralStorageConfig storageConfig); static AgentConfig upgradeOldAgentConfig(AgentConfig oldAgentConfig);  }