package org.apache.mesos.dcos;

import org.apache.http.client.fluent.Content;
import org.apache.http.client.fluent.Request;
import org.json.JSONObject;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Optional;

/**
 * Instances of this class represent DC/OS clusters.
 */
public class DcosCluster {
    private static final String DCOS_VERSION_PATH = "/dcos-metadata/dcos-version.json";

    private final URI dcosUri;
    private Optional<DcosVersion> dcosVersion = Optional.empty();

    DcosCluster(URI dcosUri) {
        this.dcosUri = dcosUri;
    }

    public DcosCluster() throws URISyntaxException {
        this(new URI(DcosConstants.MESOS_MASTER_URI));
    }

    public URI getDcosUri() {
        return dcosUri;
    }

    public DcosVersion getDcosVersion() throws IOException, URISyntaxException {
        if (!dcosVersion.isPresent()) {
            URI versionUri = new URI(dcosUri + DCOS_VERSION_PATH);
            Content content = Request.Get(versionUri)
                    .execute().returnContent();
            JSONObject jsonObject = new JSONObject(content.toString());
            dcosVersion = Optional.of(new DcosVersion(jsonObject));
        }

        return dcosVersion.get();
    }
}

@@ -633,56 +633,38 @@
 r() 
-throws URISyntaxException %7B%0A        this(new URI
+%7B%0A        this(getUriUnchecked
 (Dco
@@ -824,28 +824,8 @@
 tion
-, URISyntaxException
  %7B%0A 
@@ -896,15 +896,23 @@
 i = 
-new URI
+getUriUnchecked
 (dco
@@ -1230,11 +1230,438 @@
 );%0A    %7D
+%0A%0A    /**%0A     * Wrapper around %7B@link URI%7D constructor which converts the checked exception to an unchecked%0A     * exception. Meant for use by static, known-good URLs.%0A     */%0A    private static URI getUriUnchecked(String path) %7B%0A        try %7B%0A            return new URI(path);%0A        %7D catch (URISyntaxException e) %7B%0A            throw new IllegalArgumentException(%22Unable to parse internal URL: %22 + path, e);%0A        %7D%0A    %7D
 %0A%7D%0A

Switch to unchecked exception for internal URIs (#123)