Java Code Examples for org.apache.brooklyn.util.text.Strings#removeFromEnd()

The following examples show how to use org.apache.brooklyn.util.text.Strings#removeFromEnd() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SaltIntegrationTest.java    From brooklyn-library with Apache License 2.0 5 votes vote down vote up
@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";
}
 
Example 2
Source File: Os.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
/** 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");
}
 
Example 3
Source File: BrooklynNodeSshDriver.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example 4
Source File: ReflectiveEntityDriverFactory.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example 5
Source File: ReflectiveEntityDriverFactory.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@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";
}
 
Example 6
Source File: ReflectiveEntityDriverFactory.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@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";
}
 
Example 7
Source File: ReflectiveEntityDriverFactory.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@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";
}
 
Example 8
Source File: GeoscalingWebClient.java    From brooklyn-library with Apache License 2.0 4 votes vote down vote up
/** 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);
}
 
Example 9
Source File: SeaCloudsPolicyRequestComposer.java    From SeaCloudsPlatform with Apache License 2.0 4 votes vote down vote up
public static String setupGrafanaInitializerPayload(SeaCloudsManagementPolicy policy, String id) {
    final String globalGrafanaOptionsJSON =
            "{  " +
                    "\"overwrite\": false," +
                    "\"dashboard\": {" +
                    "\"id\": null," +
                    "\"title\": \"" + id + " Dashboard\"," +
                    "\"tags\": [\"SeaClouds\", \"AUTOGENERATED\"]," +
                    "\"style\": \"dark\"," +
                    "\"timezone\": \"browser\"," +
                    "\"editable\": true," +
                    "\"hideControls\": false," +
                    "\"sharedCrosshair\": true," +
                    "\"time\": { \"from\": \"now-6h\", \"to\": \"now\" }," +
                    "\"timepicker\": { " +
                    "                   \"refresh_intervals\": [\"1m\", \"1h\", \"1d\"]," +
                    "                   \"time_options\": [\"1h\", \"12h\", \"24h\", \"2d\", \"7d\", \"30d\"] " +
                    "}," +
                    "\"templating\": { \"list\": []  }," +
                    "\"annotations\": { \"list\": []  }," +
                    "\"schemaVersion\": 7," +
                    "\"version\": 1," +
                    "\"links\": []," +
                    "\"rows\": [";


    String rowOptions = "";

    for (String metricName : policy.extractMetricNames()) {
        int index = 0;
        String currentRow =
                "{" +
                        "\"collapse\": false," +
                        "\"editable\": false," +
                        "\"height\": \"250px\"," +
                        "\"panels\": [{" +
                        "                  \"id\":" + index + "," +
                        "                  \"aliasColors\": {}," +
                        "                  \"bars\": false," +
                        "                  \"datasource\": null," +
                        "                  \"editable\": true," +
                        "                  \"error\": false," +
                        "                  \"fill\": 1," +
                        "                  \"grid\": { \"leftLogBase\": 1, \"leftMax\": null, \"leftMin\": null, \"rightLogBase\": 1, \"rightMax\": null, \"rightMin\": null, \"threshold1\": null,  \"threshold1Color\": \"rgba(216, 200, 27, 0.27)\", \"threshold2\": null, \"threshold2Color\": \"rgba(234, 112, 112, 0.22)\" }," +
                        "                  \"legend\": { \"avg\": true, \"current\": false, \"max\": true, \"min\": true, \"show\": true, \"total\": false, \"values\": false}," +
                        "                  \"lines\": true," +
                        "                  \"linewidth\": 2," +
                        "                  \"links\": []," +
                        "                  \"nullPointMode\": \"connected\"," +
                        "                  \"percentage\": false," +
                        "                  \"pointradius\": 5," +
                        "                  \"points\": false," +
                        "                  \"renderer\": \"flot\"," +
                        "                  \"seriesOverrides\": []," +
                        "                  \"span\": 12," +
                        "                  \"stack\": false," +
                        "                  \"steppedLine\": false," +
                        "                  \"targets\": [{ " +
                        "                                    \"column\": \"value\"," +
                        "                                    \"function\": \"mean\"," +
                        "                                    \"query\": \"select mean(value) from \\\"" + metricName + "\\\" where $timeFilter group by time($interval) order asc\"," +
                        "                                    \"refId\": \"A\"," +
                        "                                    \"series\": \"" + metricName + "\"" +
                        "                               }]," +
                        "                  \"timeFrom\": null," +
                        "                  \"timeShift\": null," +
                        "                  \"title\": \"" + metricName + "\"," +
                        "                  \"tooltip\": { \"shared\": true, \"value_type\": \"cumulative\"}," +
                        "                  \"type\": \"graph\"," +
                        "                  \"x-axis\": true," +
                        "                  \"y-axis\": true," +
                        "                  \"y_formats\": [\"short\",\"short\"]" +
                        "              }]," +
                        "      \"title\": \"" + id + "\"" +
                        "},";
        rowOptions += currentRow;
    }

    // Remove last ,
    rowOptions = Strings.removeFromEnd(rowOptions, ",");
    return globalGrafanaOptionsJSON + rowOptions + "] } }";
}