/** e.g. editRecord("foo", "A", "1.2.3.4"), which assuming this domain is "bar.com", will create A record for foo.bar.com. * <p> * or editRecord("*.foo", "CNAME", "foo.bar.com") to map everything at *.foo.bar.com to foo.bar.com */ public void editRecord(String subdomainPart, String type, String content) { subdomainPart = Strings.removeFromEnd(subdomainPart, "."+name); editSubdomainRecord(id, subdomainPart, type, content); }
@Override public <D extends EntityDriver> String inferDriverClassName(DriverDependentEntity<D> entity, Class<D> driverInterface, Location location) { String driverInterfaceName = driverInterface.getName(); if (!(location instanceof SshMachineLocation)) return null; if (!driverInterfaceName.endsWith("Driver")) { throw new IllegalArgumentException(String.format("Driver name [%s] doesn't end with 'Driver'; cannot auto-detect SshDriver class name", driverInterfaceName)); } return Strings.removeFromEnd(driverInterfaceName, "Driver")+"SshDriver"; } }
@Override public <D extends EntityDriver> String inferDriverClassName(DriverDependentEntity<D> entity, Class<D> driverInterface, Location location) { if (driverInterface.getSimpleName().equals(expectedPattern)) { // i'd like to do away with drivers altogether, but if people *really* need to use this and suppress the warning, // they can use the full class rename LOG.warn("Using discouraged driver simple class rename to find "+replacement+" for "+expectedPattern+"; it is recommended to set getDriverInterface() or newDriver() appropriately"); return Strings.removeFromEnd(driverInterface.getName(), expectedPattern)+replacement; } return null; } }
@Override public <D extends EntityDriver> String inferDriverClassName(DriverDependentEntity<D> entity, Class<D> driverInterface, Location location) { String driverInterfaceName = driverInterface.getName(); if (!(location instanceof PaasLocation)) return null; if (!driverInterfaceName.endsWith("Driver")) { throw new IllegalArgumentException(String.format("Driver name [%s] doesn't end with 'Driver'; cannot auto-detect PaasDriver class name", driverInterfaceName)); } return Strings.removeFromEnd(driverInterfaceName, "Driver") + ((PaasLocation) location).getPaasProviderName() + "Driver"; } }
/** fails if the dir is not "safe" for deletion, currently length <= 2 or the home directory */ protected static void checkSafe(File dir) throws IOException { String dp = dir.getAbsolutePath(); dp = Strings.removeFromEnd(dp, "/"); if (dp.length()<=2) throw new IOException("Refusing instruction to delete "+dir+": name too short"); if (Os.home().equals(dp)) throw new IOException("Refusing instruction to delete "+dir+": it's the home directory"); }
public void testRemoveFromEnd() { assertEquals(Strings.removeFromEnd("", "bar"), ""); assertEquals(Strings.removeFromEnd(null, "bar"), null); assertEquals(Strings.removeFromEnd("foobar", "bar"), "foo"); assertEquals(Strings.removeFromEnd("foo", "bar"), "foo"); // test they are applied in order }
public void testRemoveFromEnd2() { assertEquals(Strings.removeFromEnd("xyz", "z"), "xy"); assertEquals(Strings.removeFromEnd("xyz", "."), "xyz"); assertEquals(Strings.removeFromEnd("http://foo.com/", "/"), "http://foo.com"); }
public static String getContainerName(Entity target) { String unique = getUniqueContainerName(target); String suffix = "_" + target.getId(); return Strings.removeFromEnd(unique, suffix); }
@Override public <D extends EntityDriver> String inferDriverClassName(DriverDependentEntity<D> entity, Class<D> driverInterface, Location location) { String driverInterfaceName = driverInterface.getName(); // TODO: use a proper registry later on try { Class<?> winRmLocationClass = new ClassLoaderUtils(this, entity).loadClass("org.apache.brooklyn.software-winrm", BrooklynVersion.get(), "org.apache.brooklyn.location.winrm.WinRmMachineLocation"); if (!winRmLocationClass.isInstance(location)) return null; } catch (ClassNotFoundException ex) { return null; } if (!driverInterfaceName.endsWith("Driver")) { throw new IllegalArgumentException(String.format("Driver name [%s] doesn't end with 'Driver'; cannot auto-detect WinRmDriver class name", driverInterfaceName)); } return Strings.removeFromEnd(driverInterfaceName, "Driver")+"WinRmDriver"; } }
@Override public <D extends EntityDriver> String inferDriverClassName(DriverDependentEntity<D> entity, Class<D> driverInterface, Location location) { String driverInterfaceName = driverInterface.getName(); if (!(location instanceof SimulatedLocation)) { return null; } if (!driverInterfaceName.endsWith("Driver")) { throw new IllegalArgumentException(String.format("Driver name [%s] doesn't end with 'Driver'; cannot auto-detect SshDriver class name", driverInterfaceName)); } return Strings.removeFromEnd(driverInterfaceName, "Driver") + "SimulatedDriver"; } }
@Override public String getArchiveNameFormat() { String subpath = entity.getConfig(BrooklynNode.SUBPATH_IN_ARCHIVE); if (subpath==null) { // assume the dir name is `basename-VERSION` where download link is `basename-VERSION-dist.tar.gz` String uploadUrl = entity.getConfig(BrooklynNode.DISTRO_UPLOAD_URL); String origDownloadName = uploadUrl; if (origDownloadName==null) origDownloadName = entity.getAttribute(BrooklynNode.DOWNLOAD_URL); if (origDownloadName!=null) { // BasicDownloadResolver makes it crazy hard to get the template-evaluated value of DOWNLOAD_URL origDownloadName = DownloadSubstituters.substitute(origDownloadName, DownloadSubstituters.getBasicEntitySubstitutions(this)); origDownloadName = Urls.decode(origDownloadName); origDownloadName = Urls.getBasename(origDownloadName); String downloadName = origDownloadName; downloadName = Strings.removeFromEnd(downloadName, ".tar.gz"); downloadName = Strings.removeFromEnd(downloadName, ".tgz"); downloadName = Strings.removeFromEnd(downloadName, ".zip"); if (!downloadName.equals(origDownloadName)) { downloadName = Strings.removeFromEnd(downloadName, "-dist"); subpath = downloadName; } } } if (subpath==null) subpath = "brooklyn-dist-%s"; return subpath; }