public String getSummary() { if (summary!=null) return summary; return Strings.maxlen(Strings.join(commands, " ; "), 160); }
@Test public void testMaxlen() { Assert.assertEquals(Strings.maxlen("hello world", 5), "hello"); Assert.assertEquals(Strings.maxlenWithEllipsis("hello world", 9), "hello ..."); Assert.assertEquals(Strings.maxlenWithEllipsis("hello world", 7, "--"), "hello--"); }
protected String generateNewIdReservingLength(ConfigBag setup, int lengthToReserve) { int len = getMaxNameLength(setup); // decrement by e.g. 9 chars because jclouds adds that (dash plus 8 for hex id) len -= lengthToReserve; if (len<=0) return ""; return Strings.maxlen(generateNewIdOfLength(setup, len), len); }
@Override public String apply(Object input) { System.out.println(Strings.maxlen(Strings.toString(input), 80)); return Strings.toString(input); } }
@Test public void testGenerateGroupIdInVcloud() { ConfigBag cfg = new ConfigBag() .configure(JcloudsLocationConfig.CLOUD_PROVIDER, "vcloud") .configure(JcloudsLocationConfig.CALLER_CONTEXT, "!mycontext!"); String result = new JcloudsMachineNamer().generateNewGroupId(cfg); log.info("test mycontext vcloud group id gives: "+result); // brooklyn-user-!mycontext!-1234 // br-<code>-<user>-myco-1234 Assert.assertTrue(result.length() <= 24-4-1, "result: "+result); String user = System.getProperty("user.name"); String userExt = Strings.maxlen(user, 2).toLowerCase(); // Username can be omitted if it is longer than the rules defined in BasicCloudMachineNamer() if (user.length() <= 4) { // (length 2 will happen if user is brooklyn, to avoid brooklyn-brooklyn at start!) Assert.assertTrue(result.indexOf(userExt) >= 0); } Assert.assertTrue(result.indexOf("-myc") >= 0); }
@Test public void testGenerateNewMachineName() { TestApplication app = mgmt.getEntityManager().createEntity(EntitySpec.create(TestApplication.class).displayName("TistApp")); TestEntity child = app.createAndManageChild(EntitySpec.create(TestEntity.class).displayName("TestEnt")); ConfigBag cfg = new ConfigBag() .configure(CloudLocationConfig.CALLER_CONTEXT, child); BasicCloudMachineNamer namer = new BasicCloudMachineNamer(); String result = namer.generateNewMachineUniqueName(cfg); Assert.assertTrue(result.length() <= namer.getMaxNameLength(cfg)); String user = Strings.maxlen(System.getProperty("user.name"), 4).toLowerCase(); Assert.assertTrue(result.indexOf(user) >= 0); Assert.assertTrue(result.indexOf("-tistapp-") >= 0); Assert.assertTrue(result.indexOf("-testent-") >= 0); Assert.assertTrue(result.indexOf("-"+Strings.maxlen(app.getId(), 4).toLowerCase()) >= 0); Assert.assertTrue(result.indexOf("-"+Strings.maxlen(child.getId(), 4).toLowerCase()) >= 0); }
displayNameAutoGenerated = false; } else if (isLegacyConstruction()) { displayName.set(getClass().getSimpleName()+":"+Strings.maxlen(getId(), 4)); displayNameAutoGenerated = true;
@Test public void testGenerateGroupIdWithEntity() { TestApplication app = mgmt.getEntityManager().createEntity(EntitySpec.create(TestApplication.class).displayName("TistApp")); TestEntity child = app.createAndManageChild(EntitySpec.create(TestEntity.class).displayName("TestEnt")); ConfigBag cfg = new ConfigBag() .configure(CloudLocationConfig.CALLER_CONTEXT, child); String result = new BasicCloudMachineNamer().generateNewGroupId(cfg); log.info("test entity child group id gives: "+result); // e.g. brooklyn-alex-tistapp-uube-testent-xisg-rwad Assert.assertTrue(result.length() <= 60); String user = Strings.maxlen(System.getProperty("user.name"), 4).toLowerCase(); Assert.assertTrue(result.indexOf(user) >= 0); Assert.assertTrue(result.indexOf("-tistapp-") >= 0); Assert.assertTrue(result.indexOf("-testent-") >= 0); Assert.assertTrue(result.indexOf("-"+Strings.maxlen(app.getId(), 4).toLowerCase()) >= 0); Assert.assertTrue(result.indexOf("-"+Strings.maxlen(child.getId(), 4).toLowerCase()) >= 0); }
/** * Invoked by {@link EntityManagementSupport} when this entity is becoming managed (i.e. it has a working * management context, but before the entity is visible to other entities), including during a rebind. */ public void onManagementStarting() { if (isLegacyConstruction()) { entityType.setName(getEntityTypeName()); if (displayNameAutoGenerated) displayName.set(getEntityType().getSimpleName()+":"+Strings.maxlen(getId(), 4)); } }
@Override public void setManagementContext(ManagementContextInternal managementContext) { super.setManagementContext(managementContext); getManagementSupport().setManagementContext(managementContext); entityType.setName(getEntityTypeName()); if (displayNameAutoGenerated) displayName.set(getEntityType().getSimpleName()+":"+Strings.maxlen(getId(), 4)); }