public boolean getHttpsEnabled() { if (httpsEnabled!=null) return httpsEnabled; httpsEnabled = managementContext.getConfig().getConfig(BrooklynWebConfig.HTTPS_REQUIRED); return httpsEnabled; }
/** looks for the given application instance, first by ID then by name * * @throws 404 if not found */ public Application getApplication(String application) { Entity e = mgmt.getEntityManager().getEntity(application); if (e!=null && e instanceof Application) return (Application)e; for (Application app: mgmt.getApplications()) { if (app.getId().equals(application)) return app; if (application.equalsIgnoreCase(app.getDisplayName())) return app; } throw notFound("Application '%s' not found", application); }
public Task<?> destroy(final Application application) { return mgmt.getExecutionManager().submit(new Runnable() { @Override public void run() { ((EntityInternal)application).destroy(); mgmt.getEntityManager().unmanage(application); } }); }
/** stops, destroys, and unmanages all apps in the given context, * and then terminates the management context */ public static void destroyAll(ManagementContext mgmt) { Exception error = null; if (mgmt instanceof NonDeploymentManagementContext) { // log here because it is easy for tests to destroyAll(app.getMgmtContext()) // which will *not* destroy the mgmt context if the app has been stopped! log.warn("Entities.destroyAll invoked on non-deployment "+mgmt+" - not likely to have much effect! " + "(This usually means the mgmt context has been taken from entity has been destroyed. " + "To destroy other things on the management context ensure you keep a handle to the context " + "before the entity is destroyed, such as by creating the management context first.)"); } if (!mgmt.isRunning()) return; log.debug("destroying all apps in "+mgmt+": "+mgmt.getApplications()); for (Application app: mgmt.getApplications()) { log.debug("destroying app "+app+" (managed? "+isManaged(app)+"; mgmt is "+mgmt+")"); try { destroy(app); log.debug("destroyed app "+app+"; mgmt now "+mgmt); } catch (Exception e) { log.warn("problems destroying app "+app+" (mgmt now "+mgmt+", will rethrow at least one exception): "+e); if (error==null) error = e; } } if (mgmt instanceof ManagementContextInternal) ((ManagementContextInternal)mgmt).terminate(); if (error!=null) throw Exceptions.propagate(error); }
public static DownloadResolver newDownloader(EntityDriver driver, Map<String,?> properties) { EntityInternal internal = (EntityInternal) driver.getEntity(); return internal.getManagementContext().getEntityDownloadsManager().newDownloader(driver, properties); }
protected EntityManager getEntityManager() { return getManagementContext().getEntityManager(); }
public Map<Location, Integer> countLeafEntitiesByLocatedLocations() { Map<Location, Integer> result = new LinkedHashMap<Location, Integer>(); for (Entity e: context.getApplications()) { countLeafEntitiesByLocatedLocations(e, null, result); } return result; }
public LocationRegistry getLocationRegistry() { return mgmt.getLocationRegistry(); }
protected FixedListMachineProvisioningLocation<SshMachineLocation> newLocationFromString(String spec, brooklyn.location.LocationRegistry registry, Map properties, Map locationFlags) { Matcher matcher = PATTERN.matcher(spec); if (!matcher.matches()) { throw new IllegalArgumentException("Invalid location '" + spec + "'; must specify something like host:(\"1.1.1.1\")"); } String namedLocation = (String) locationFlags.get("named"); Map<String, Object> filteredProperties = new LocationPropertiesFromBrooklynProperties().getLocationProperties(null, namedLocation, properties); MutableMap<String, Object> flags = MutableMap.<String, Object>builder().putAll(filteredProperties).putAll(locationFlags).removeAll("named").build(); String args = matcher.group(2); String target = "byon:(hosts=" + args + ")"; if (!managementContext.getLocationRegistry().canResolve(target)) { throw new IllegalArgumentException("Invalid target location '" + target + "'; must be resolvable location"); } return managementContext.getLocationManager().createLocation(LocationSpec.create(SingleMachineProvisioningLocation.class) .configure("location", target) .configure("locationFlags", flags)); }
protected void assertNotYetManaged() { if (!inConstruction && (managementContext != null && managementContext.getLocationManager().isManaged(this))) { LOG.warn("Configuration being made to {} after deployment; may not be supported in future versions", this); } //throw new IllegalStateException("Cannot set configuration "+key+" on active location "+this) }
ctx.getCatalog().getCatalogItems(); stopAllApps(ctx.getApplications()); } else {
private void refreshSensors() { ManagementContext managementContext = getManagementContext(); BasicExecutionManager execManager = (BasicExecutionManager) (managementContext != null ? managementContext.getExecutionManager() : null); LocalSubscriptionManager subsManager = (LocalSubscriptionManager) (managementContext != null ? managementContext.getSubscriptionManager() : null); if (managementContext != null) { setAttribute(TOTAL_EFFECTORS_INVOKED, ((ManagementContextInternal)managementContext).getTotalEffectorInvocations()); } if (execManager != null) { setAttribute(TOTAL_TASKS_SUBMITTED, execManager.getTotalTasksSubmitted()); setAttribute(NUM_INCOMPLETE_TASKS, execManager.getNumIncompleteTasks()); setAttribute(NUM_ACTIVE_TASKS, execManager.getNumActiveTasks()); } if (subsManager != null) { setAttribute(TOTAL_EVENTS_PUBLISHED, subsManager.getTotalEventsPublished()); setAttribute(TOTAL_EVENTS_DELIVERED, subsManager.getTotalEventsDelivered()); setAttribute(NUM_SUBSCRIPTIONS, subsManager.getNumSubscriptions()); } } }
BrooklynMementoImpl.Builder builder = BrooklynMementoImpl.builder(); for (Application app : managementContext.getApplications()) { builder.applicationIds.add(app.getId()); for (Entity entity : managementContext.getEntities()) { builder.entities.put(entity.getId(), entity.getRebindSupport().getMemento());
public BrooklynCatalog getCatalog() { return mgmt.getCatalog(); }
nonDeploymentManagementContext.setMode(NonDeploymentManagementContext.NonDeploymentManagementContextMode.MANAGEMENT_STARTING); nonDeploymentManagementContext.getSubscriptionManager().setDelegate((AbstractSubscriptionManager) managementContext.getSubscriptionManager()); nonDeploymentManagementContext.getSubscriptionManager().startDelegatingForSubscribing();
@Override public void install() { //mysql-${version}-${driver.osTag}.tar.gz DownloadResolver resolver = ((EntityInternal)entity).getManagementContext().getEntityDownloadsManager().newDownloader( this, ImmutableMap.of("filename", getInstallFilename())); List<String> urls = resolver.getTargets(); String saveAs = resolver.getFilename(); _expandedInstallDir = getInstallDir()+"/"+resolver.getUnpackedDirectoryName(format("mysql-%s-%s", getVersion(), getOsTag())); List<String> commands = new LinkedList<String>(); commands.add(BashCommands.INSTALL_TAR); commands.add(BashCommands.INSTALL_CURL); commands.add("echo installing extra packages"); commands.add(installPackage(ImmutableMap.of("yum", "libgcc_s.so.1"), null)); commands.add(installPackage(ImmutableMap.of("yum", "libaio.so.1 libncurses.so.5", "apt", "libaio1 libaio-dev"), null)); // these deps are needed on some OS versions but others don't need them so ignore failures (ok(...)) commands.add(ok(installPackage(ImmutableMap.of("yum", "libaio", "apt", "ia32-libs"), null))); commands.add("echo finished installing extra packages"); commands.addAll(commandsToDownloadUrlsAs(urls, saveAs)); commands.add(format("tar xfvz %s", saveAs)); newScript(INSTALLING). body.append(commands).execute(); }
@Override public Collection<Entity> getEntities() { if (isInitialManagementContextReal()) { return initialManagementContext.getEntityManager().getEntities(); } else { return Collections.emptyList(); } }
public Map<Location, Integer> countLeafEntitiesByLocatedLocations() { Map<Location, Integer> result = new LinkedHashMap<Location, Integer>(); for (Entity e: context.getApplications()) { countLeafEntitiesByLocatedLocations(e, null, result); } return result; }
public LocationRegistry getLocationRegistry() { return mgmt.getLocationRegistry(); }
protected Location newLocationFromString(String spec, brooklyn.location.LocationRegistry registry, Map properties, Map locationFlags) { Matcher matcher = PATTERN.matcher(spec); if (!matcher.matches()) { throw new IllegalArgumentException("Invalid location '" + spec + "'; must specify something like single(named:foo)"); } String namedLocation = (String) locationFlags.get("named"); String args = matcher.group(2); Map<String,?> locationArgs = KeyValueParser.parseMap(args); Map<String, Object> filteredProperties = new LocationPropertiesFromBrooklynProperties().getLocationProperties(null, namedLocation, properties); MutableMap<String, Object> flags = MutableMap.<String, Object>builder() .putAll(filteredProperties) .putAll(locationFlags) .removeAll("named") .putAll(locationArgs).build(); if (locationArgs.get("target") == null) { throw new IllegalArgumentException("target must be specified in single-machine spec"); } String target = locationArgs.get("target").toString(); locationArgs.remove("target"); if (!managementContext.getLocationRegistry().canResolve(target)) { throw new IllegalArgumentException("Invalid target location '" + target + "'; must be resolvable location"); } return managementContext.getLocationManager().createLocation(LocationSpec.create(SingleMachineProvisioningLocation.class) .configure("location", target) .configure("locationFlags", flags)); }