@Test public void testResolvesPropertiesInSpec() throws Exception { LocationInternal location = resolve("localhost(privateKeyFile=myprivatekeyfile,name=myname)"); assertTrue(location instanceof LocalhostMachineProvisioningLocation); assertEquals(location.getDisplayName(), "myname"); assertEquals(location.config().getBag().getStringKey("privateKeyFile"), "myprivatekeyfile"); }
public static void dumpInfo(Policy pol, Writer out, String currentIndentation, String tab) throws IOException { out.append(currentIndentation+pol.toString()+"\n"); for (ConfigKey<?> key : sortConfigKeys(pol.getPolicyType().getConfigKeys())) { Maybe<Object> val = ((BrooklynObjectInternal)pol).config().getRaw(key); if (!isTrivial(val)) { out.append(currentIndentation+tab+tab+key); out.append(" = "); if (isSecret(key.getName())) out.append("xxxxxxxx"); else out.append(""+val.get()); out.append("\n"); } } out.flush(); }
public Object get(boolean preferJson, String application, String entityToken, String configKeyName, Boolean raw) { Entity entity = brooklyn().getEntity(application, entityToken); ConfigKey<?> ck = findConfig(entity, configKeyName); if (!Entitlements.isEntitled(mgmt().getEntitlementManager(), Entitlements.SEE_ENTITY, entity)) { throw WebResourceUtils.forbidden("User '%s' is not authorized to see entity '%s'", Entitlements.getEntitlementContext().user(), entity); } if (!Entitlements.isEntitled(mgmt().getEntitlementManager(), Entitlements.SEE_CONFIG, new EntityAndItem<String>(entity, ck.getName()))) { throw WebResourceUtils.forbidden("User '%s' is not authorized to see entity '%s' config '%s'", Entitlements.getEntitlementContext().user(), entity, ck.getName()); } Object value = ((EntityInternal)entity).config().getRaw(ck).orNull(); return resolving(value).preferJson(preferJson).asJerseyOutermostReturnValue(true).raw(raw).context(entity).immediately(true).renderAs(ck).resolve(); }
@Override public void init() { super.init(); if (config().getRaw(SENSOR_FAILED).isAbsent()) { config().set(SENSOR_FAILED, CONNECTION_FAILED); } if (config().getRaw(SENSOR_RECOVERED).isAbsent()) { config().set(SENSOR_RECOVERED, CONNECTION_RECOVERED); } if (config().getRaw(POLL_PERIOD).isAbsent()) { config().set(POLL_PERIOD, Duration.ONE_MINUTE); } uniqueTag = DEFAULT_UNIQUE_TAG; }
public T call() { T blockingValue = entity.config().get(configKey); Maybe<T> immediateValue = ((EntityInternal)entity).config().getNonBlocking(configKey); assertEquals(immediateValue.get(), blockingValue); return blockingValue; }}); return future.get(Asserts.DEFAULT_LONG_TIMEOUT.toMilliseconds(), TimeUnit.MILLISECONDS);
@Override protected String getInstallLabelExtraSalt() { return (String)((EntityInternal)getEntity()).config().getRaw(ConfigKeys.newStringConfigKey("salt")).or((String)null); } }
private Integer hashCodeIfResolved(ConfigKey<?> ...keys) { int hash = 0; for (ConfigKey<?> k: keys) { Maybe<?> value = ((ConfigurationSupportInternal)getEntity().config()).getNonBlocking(k); if (value.isPresent()) { hash = hash*31 + (value.get()==null ? 0 : value.get().hashCode()); } } return hash; }
protected void setInstallLabel() { if (((EntityInternal)getEntity()).config().getLocalRaw(SoftwareProcess.INSTALL_UNIQUE_LABEL).isPresentAndNonNull()) return; getEntity().config().set(SoftwareProcess.INSTALL_UNIQUE_LABEL, getEntity().getEntityType().getSimpleName()+ (Strings.isNonBlank(getVersion()) ? "_"+getVersion() : "")+ (Strings.isNonBlank(getInstallLabelExtraSalt()) ? "_"+getInstallLabelExtraSalt() : "") ); }
@Test public void testRebindPreservesGetConfigWithDefault() throws Exception { MyEntity origE = origApp.createAndManageChild(EntitySpec.create(MyEntity.class)); assertNull(origE.getConfig(MyEntity.MY_CONFIG)); assertEquals(((EntityInternal)origE).config().getRaw(MyEntity.MY_CONFIG).or("mydefault"), "mydefault"); newApp = rebind(); MyEntity newE = (MyEntity) Iterables.find(newApp.getChildren(), Predicates.instanceOf(MyEntity.class)); assertNull(newE.getConfig(MyEntity.MY_CONFIG)); assertEquals(((EntityInternal)newE).config().getRaw(MyEntity.MY_CONFIG).or("mydefault"), "mydefault"); }
protected void checkConfig() { Collection<? extends AttributeSensor<?>> sensors = getConfig(SENSORS); Maybe<Object> rawMapMatching = config().getRaw(MAP_MATCHING); String mapMatching = config().get(MAP_MATCHING); if (sensors == null || sensors.isEmpty()) { if (Strings.isBlank(mapMatching)) { throw new IllegalStateException(this+" requires 'sensors' config (when 'mapMatching' is explicitly blank)"); } } else if (rawMapMatching.isPresent()) { throw new IllegalStateException(this+" must not have explicit 'mapMatching' and 'sensors' config"); } }
@SuppressWarnings("unchecked") @Override protected Sensor<FailureDescriptor> getSensorFailed() { Maybe<Object> sensorFailed = config().getRaw(SENSOR_FAILED); if (sensorFailed.isPresent()) { return (Sensor<FailureDescriptor>)sensorFailed.get(); } else { return CONNECTION_FAILED; } }
private void assertMachineEquals(JcloudsSshMachineLocation actual, JcloudsSshMachineLocation expected, boolean expectNoOsDetails) { String errmsg = "actual="+actual.toVerboseString()+"; expected="+expected.toVerboseString(); assertEquals(actual.getId(), expected.getId(), errmsg); assertEquals(actual.getJcloudsId(), expected.getJcloudsId(), errmsg); if (expectNoOsDetails) { assertOsDetailEquals(actual.getOptionalOsDetails(), Optional.<OsDetails>absent()); } else { assertOsDetailEquals(actual.getOptionalOsDetails(), expected.getOptionalOsDetails()); } assertEquals(actual.getSshHostAndPort(), expected.getSshHostAndPort()); assertEquals(actual.getPrivateAddress(), expected.getPrivateAddress()); assertConfigBagEquals(actual.config().getBag(), expected.config().getBag(), errmsg); }
@Test(dataProvider = "testModeDataProvider") public void testMode(NetworkMode mode, Set<HostAndPort> reachableIps, String expectedIp) throws Exception { final DefaultConnectivityResolver customizer = new DefaultConnectivityResolver(ImmutableMap.of( DefaultConnectivityResolver.NETWORK_MODE, mode, DefaultConnectivityResolver.CHECK_CREDENTIALS, false)); initNodeCreatorAndJcloudsLocation(newNodeCreator(), ImmutableMap.of( JcloudsLocationConfig.CONNECTIVITY_RESOLVER, customizer)); ConnectivityResolverOptions options = newResolveOptionsForIps(reachableIps, Duration.millis(100)).build(); ConfigBag configBag = jcloudsLocation.config().getBag(); ManagementAddressResolveResult result = customizer.resolve(jcloudsLocation, newNodeMetadata(), configBag, options); assertEquals(result.hostAndPort().getHostText(), expectedIp); }
@SuppressWarnings("unchecked") @Override protected Sensor<FailureDescriptor> getSensorRecovered() { Maybe<Object> sensorRecovered = config().getRaw(SENSOR_RECOVERED); if (sensorRecovered.isPresent()) { return (Sensor<FailureDescriptor>)sensorRecovered.get(); } else { return CONNECTION_RECOVERED; } }
protected String getCreateUserStatementsFor(Map<ConfigKey<?>,?> config) { BailOutJcloudsLocation jl = BailOutJcloudsLocation.newBailOutJcloudsLocation( managementContext, MutableMap.<ConfigKey<?>, Object>builder() .put(JcloudsLocationConfig.LOGIN_USER, "root").put(JcloudsLocationConfig.LOGIN_USER_PASSWORD, "m0ck") .put(JcloudsLocationConfig.USER, "bob").put(JcloudsLocationConfig.LOGIN_USER_PASSWORD, "b0b") .putAll(config).build()); CreateUserStatements creation = CreateUserStatements.get(jl, null, jl.config().getBag()); return new StatementList(creation.statements()).render(OsFamily.UNIX); }
private void assertReachability(boolean expectedReachable, SshMachineLocation machine, String addr, String msg) { SshMachineLocation tmpMachine = managementContext.getLocationManager().createLocation(LocationSpec.create(SshMachineLocation.class) .configure(machine.config().getBag().getAllConfig()) .configure("address", addr)); try { boolean sshable = tmpMachine.isSshable(); assertEquals(sshable, expectedReachable, addr+" not sshable; "+msg); } finally { Locations.unmanage(tmpMachine); } }
private void checkReferences(final Entity entity, Map<ConfigKey<Entity>, Entity> keyToEntity) throws Exception { for (final ConfigKey<Entity> key : keyToEntity.keySet()) { try { Assert.assertEquals(getResolvedConfigInTask(entity, key).get(), keyToEntity.get(key), "For entity " + entity.toString() + ":"); } catch (Throwable t) { Exceptions.propagateIfFatal(t); Assert.fail("Wrong value for "+entity+":"+key+", "+((EntityInternal)entity).config().getLocalRaw(key)+": "+t, t); } } }
@Test public void testUsingDeprecatedNameSubkey() throws Exception { EntityInternal entity = app.addChild(EntitySpec.create(MyEntity.class) .configure("confMapDeepMerge.mykey", "myval")); assertEquals(entity.config().get(MyEntity.CONF_MAP_DEEP_MERGE), ImmutableMap.of("mykey", "myval")); }