/** convenience for starting an entity, esp a new Startable instance which has been created dynamically * (after the application is started) */ public static void start(Entity e, Collection<? extends Location> locations) { if (!isManaged(e) && !manage(e)) { log.warn("Using deprecated discouraged mechanism to start management -- Entities.start(Application, Locations) -- caller should create and use the preferred management context"); startManagement(e); } if (e instanceof Startable) Entities.invokeEffector(e, e, Startable.START, MutableMap.of("locations", locations)).getUnchecked(); }
public void attemptLegacyAutodeployment(String effectorName) { synchronized (this) { if (managementContext != null) { log.warn("Autodeployment suggested but not required for " + entity + "." + effectorName); return; } if (entity instanceof Application) { log.warn("Autodeployment with new management context triggered for " + entity + "." + effectorName + " -- will not be supported in future. Explicit manage call required."); if (initialManagementContext != null) { initialManagementContext.getEntityManager().manage(entity); } else { Entities.startManagement(entity); } return; } } if ("start".equals(effectorName)) { Entity e=entity; if (e.getParent()!=null && ((EntityInternal)e.getParent()).getManagementSupport().isDeployed()) { log.warn("Autodeployment in parent's management context triggered for "+entity+"."+effectorName+" -- will not be supported in future. Explicit manage call required."); ((EntityInternal)e.getParent()).getManagementContext().getEntityManager().manage(entity); return; } } log.warn("Autodeployment not available for "+entity+"."+effectorName); }
@Test public void testStartManagementFailsIfAppDeleted() throws Exception { TestApplication app2 = mgmt.getEntityManager().createEntity(EntitySpec.create(TestApplication.class)); Entities.unmanage(app2); try { Entities.startManagement(app2, mgmt); fail("Managed deleted app "+app2+" in "+mgmt); } catch (IllegalStateException e) { if (!(e.toString().contains("No concrete entity known"))) throw e; } }
@Test public void testLegacyConstructionSetsDefaultDisplayName() throws Exception { app = new TestApplicationImpl(); MyEntity entity = new MyEntityImpl(app); assertTrue(entity.getDisplayName().startsWith("MyEntityImpl:"+entity.getId().substring(0,4)), "displayName="+entity.getDisplayName()); Entities.startManagement(app, LocalManagementContextForTests.newInstance()); assertTrue(entity.getDisplayName().startsWith("MyEntity:"+entity.getId().substring(0,4)), "displayName="+entity.getDisplayName()); }
@Test public void testStartManagementIsNoop() throws Exception { TestApplication app2 = mgmt.getEntityManager().createEntity(EntitySpec.create(TestApplication.class)); assertTrue(Entities.isManaged(app2)); Entities.startManagement(app2, mgmt); assertTrue(Entities.isManaged(app2)); listener.assertEventsEqualsEventually(ImmutableList.of(new ChangeEvent(ChangeType.ADDED, app2))); }
@Test public void testStartManagementOfEntityIsNoop() throws Exception { Entity app2 = mgmt.getEntityManager().createEntity(EntitySpec.create(TestApplication.class)); assertTrue(Entities.isManaged(app2)); Entities.startManagement(app2); assertTrue(Entities.isManaged(app2)); listener.assertEventsEqualsEventually(ImmutableList.of(new ChangeEvent(ChangeType.ADDED, app2))); }