@Override public void setManagementContext(ManagementContext managementContext) { if (portForwardManager == null) { portForwardManager = (PortForwardManager) managementContext.getLocationRegistry().resolve("portForwardManager(scope=global)"); } }
@Override public void deregister() { if (locationRegistrationId != null) { getManagementContext().getLocationRegistry().removeDefinedLocation(locationRegistrationId); } }
@VisibleForTesting public static void addNamedLocationLocalhost(ManagementContext mgmt) { if (!mgmt.getConfig().getConfig(LocalhostLocationResolver.LOCALHOST_ENABLED)) { throw new IllegalStateException("Localhost is disabled."); } // ensure localhost is added (even on windows, it's just for testing) LocationDefinition l = mgmt.getLocationRegistry().getDefinedLocationByName("localhost"); if (l==null) mgmt.getLocationRegistry().updateDefinedLocation( BasicLocationRegistry.localhost(Identifiers.makeRandomId(8)) ); }
private void registerLocationResolver() { // Doesn't matter if the resolver is already registered through ServiceLoader. // It just overwrite the existing registration (if any). // TODO Register separate resolvers for each infrastructure instance, unregister on unmanage. LocationRegistry registry = getManagementContext().getLocationRegistry(); MesosResolver mesosResolver = new MesosResolver(); ((BasicLocationRegistry)registry).registerResolver(mesosResolver); LOG.debug("Explicitly registered mesos resolver: "+mesosResolver); }
protected PortForwardManager getPortForwardManager() { PortForwardManager portForwardManager = config().get(PORT_FORWARD_MANAGER); if (portForwardManager == null) { portForwardManager = (PortForwardManager) getManagementContext().getLocationRegistry().getLocationManaged(PortForwardManagerLocationResolver.PFM_GLOBAL_SPEC); } return portForwardManager; } }
protected JcloudsLocation newJcloudsLocation(ComputeServiceRegistry computeServiceRegistry) throws Exception { return (JcloudsLocation) mgmt().getLocationRegistry().getLocationManaged("jclouds:softlayer", ImmutableMap.of( JcloudsLocation.COMPUTE_SERVICE_REGISTRY, computeServiceRegistry, JcloudsLocation.WAIT_FOR_SSHABLE, false, JcloudsLocation.USE_JCLOUDS_SSH_INIT, false)); } }
@SuppressWarnings("unchecked") private FixedListMachineProvisioningLocation<MachineLocation> resolve(String val) { return (FixedListMachineProvisioningLocation<MachineLocation>) mgmt().getLocationRegistry().getLocationManaged(val); } }
@Test(dataProvider="fromImageId") public void testTagMapping(String regionName, String imageId, String imageOwner) { useMgmt(newMockManagementContext()); Map<String, Object> dummy = ImmutableMap.<String, Object>of("identity", "DUMMY", "credential", "DUMMY"); loc = (JcloudsLocation) mgmt().getLocationRegistry().getLocationManaged(provider + (regionName == null ? "" : ":" + regionName), dummy); ImmutableMap.Builder<String, Object> builder = ImmutableMap.<String, Object>builder().put("imageId", imageId); if (imageOwner != null) builder.put("imageOwner", imageOwner); Map<String, Object> tagMapping = builder.build(); loc.setTagMapping(ImmutableMap.<String, Map<String, ? extends Object>>of("MyEntityType", tagMapping)); Map<String, Object> flags = loc.getProvisioningFlags(ImmutableList.of("MyEntityType")); assertTrue(Maps.<String, Object>difference(flags, tagMapping).entriesOnlyOnRight().isEmpty(), "flags="+flags); }
@BeforeMethod(alwaysRun=true) @Override public void setUp() throws Exception { super.setUp(); localhost = app.getManagementContext().getLocationRegistry().getLocationManaged("localhost"); }
@BeforeMethod(alwaysRun=true) @Override public void setUp() throws Exception { super.setUp(); localhost = app.getManagementContext().getLocationRegistry().getLocationManaged("localhost"); runRecord = Files.createTempFile("testVanillaSoftwareProcess-runRecord-"+Identifiers.makeRandomId(8), ".txt"); }
private void removeAndAssert(String symbolicName) { // Deleting item: should be gone from catalog, and from location registry deleteCatalogEntity(symbolicName); assertEquals(countCatalogLocations(), 0); assertNull(mgmt().getLocationRegistry().getDefinedLocationByName(symbolicName)); }
@Test(groups = "Live", dataProvider="fromImageId") public void testProvisionVmUsingImageId(String regionName, String imageId, String imageOwner) { loc = (JcloudsLocation) mgmt().getLocationRegistry().getLocationManaged(provider + (regionName == null ? "" : ":" + regionName)); SshMachineLocation machine = obtainMachine(MutableMap.of("imageId", imageId, "imageOwner", imageOwner, JcloudsLocation.MACHINE_CREATE_ATTEMPTS, 2)); LOG.info("Provisioned {} vm {}; checking if ssh'able", provider, machine); assertTrue(machine.isSshable()); }
@Test(groups = "Live", dataProvider="fromImageDescriptionPattern") public void testProvisionVmUsingImageDescriptionPattern(String regionName, String imageDescriptionPattern, String imageOwner) { loc = (JcloudsLocation) mgmt().getLocationRegistry().getLocationManaged(provider + (regionName == null ? "" : ":" + regionName)); SshMachineLocation machine = obtainMachine(MutableMap.of("imageDescriptionRegex", imageDescriptionPattern, "imageOwner", imageOwner, JcloudsLocation.MACHINE_CREATE_ATTEMPTS, 2)); LOG.info("Provisioned {} vm {}; checking if ssh'able", provider, machine); assertTrue(machine.isSshable()); }
@Test public void testKeepsPortForwardManager() throws Exception { PortForwardManager pfm = (PortForwardManager) mgmt().getLocationRegistry().getLocationManaged(PortForwardManagerLocationResolver.PFM_GLOBAL_SPEC); BrooklynMementoRawData transformedData = assertTransformIsNoop(); assertTrue(transformedData.getLocations().containsKey(pfm.getId())); }
@Override protected Location createLocation() { // Image: {id=CENTOS_6_64, providerId=CENTOS_6_64, os={family=centos, version=6.5, description=CentOS / CentOS / 6.5-64 LAMP for Bare Metal, is64Bit=true}, description=CENTOS_6_64, status=AVAILABLE, loginUser=root} Map<String, ?> allFlags = MutableMap.<String, Object>builder() .put("provider", PROVIDER) .put("tags", ImmutableList.of(getClass().getName())) .put("vmNameMaxLength", 30) .put("imageId", "CENTOS_6_64") .build(); return mgmt.getLocationRegistry().getLocationManaged(PROVIDER, allFlags); }
@BeforeMethod(alwaysRun=true) public void setup() { testContainerName = CONTAINER_PREFIX+"-"+Identifiers.makeRandomId(8); mgmt = new LocalManagementContextForTests(BrooklynProperties.Factory.newDefault()); location = (JcloudsLocation) mgmt.getLocationRegistry().getLocationManaged(locationSpec); identity = checkNotNull(location.getConfig(LocationConfigKeys.ACCESS_IDENTITY), "identity must not be null"); credential = checkNotNull(location.getConfig(LocationConfigKeys.ACCESS_CREDENTIAL), "credential must not be null"); endpoint = location.getConfig(CloudLocationConfig.CLOUD_ENDPOINT); context = BlobStoreContextFactoryImpl.INSTANCE.newBlobStoreContext(location); }
@Override public Void call(ConfigBag parameters) { parameters.put(LOCATIONS, entity().getManagementContext().getLocationRegistry().getListOfLocationsManaged(parameters.get(LOCATIONS))); return new MethodEffector<Void>(Startable.class, "start").call(entity(), parameters.getAllConfig()); } }
private void assertAdded(String symbolicName, String expectedJavaType) { RegisteredType item = mgmt().getTypeRegistry().get(symbolicName, TEST_VERSION); assertEquals(item.getSymbolicName(), symbolicName); Assert.assertTrue(RegisteredTypes.isSubtypeOf(item, Location.class), "Expected Location, not "+item.getSuperTypes()); assertEquals(countCatalogLocations(), 1); // Item added to catalog should automatically be available in location registry LocationDefinition def = mgmt().getLocationRegistry().getDefinedLocationByName(symbolicName); assertEquals(def.getId(), symbolicName+":"+TEST_VERSION); assertEquals(def.getName(), symbolicName); LocationSpec<?> spec = mgmt().getTypeRegistry().createSpec(item, null, LocationSpec.class); assertEquals(spec.getType().getName(), expectedJavaType); }
@BeforeMethod(alwaysRun=true) @Override public void setUp() throws Exception { super.setUp(); entity = app.createAndManageChild(EntitySpec.create(TestEntity.class).displayName("mydisplayname")); group = app.createAndManageChild(EntitySpec.create(BasicGroup.class)); loc = app.getManagementContext().getLocationRegistry().getLocationManaged("localhost"); }
@Override public void init() { super.init(); if (getConfig(PORT_FORWARD_MANAGER) == null) { PortForwardManager pfm = (PortForwardManager) getManagementContext().getLocationRegistry().getLocationManaged(PortForwardManagerLocationResolver.PFM_GLOBAL_SPEC); sensors().set(PORT_FORWARD_MANAGER_LIVE, pfm); config().set(PORT_FORWARD_MANAGER, pfm); } } }