Java Code Examples for mesosphere.client.common.ModelUtils

The following examples show how to use mesosphere.client.common.ModelUtils. These examples are extracted from open source projects. 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 Project: marathon-client   Source File: MarathonClient.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * The generalized version of the method that allows more in-depth customizations via
 * {@link RequestInterceptor}s.
 *
 * @param endpoint
 * 		URL of Marathon
 * @param interceptors optional request interceptors
 * @return Marathon client
 */
public static Marathon getInstance(String endpoint, RequestInterceptor... interceptors) {

	Builder b = Feign.builder()
			.encoder(new GsonEncoder(ModelUtils.GSON))
			.decoder(new GsonDecoder(ModelUtils.GSON))
			.errorDecoder(new MarathonErrorDecoder());
	if (interceptors != null)
		b.requestInterceptors(asList(interceptors));
	String debugOutput = System.getenv(DEBUG_JSON_OUTPUT);
	if ("System.out".equals(debugOutput)) {
		System.setProperty("org.slf4j.simpleLogger.logFile", "System.out");
		System.setProperty("org.slf4j.simpleLogger.defaultLogLevel", "debug");
		b.logger(new Slf4jLogger()).logLevel(Logger.Level.FULL);
	} else if (debugOutput != null) {
		b.logger(new Logger.JavaLogger().appendToFile(debugOutput)).logLevel(Logger.Level.FULL);
	}
	b.requestInterceptor(new MarathonHeadersInterceptor());
	return b.target(Marathon.class, endpoint);
}
 
Example 2
Source Project: pravega   Source File: LoginClient.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Fetch the token from the authentication service.
 *
 *  @param loginURL           Login Url.
 *  @return Auth token.
 */
public static String getAuthToken(final String loginURL) {

    Login client = Feign.builder().client(getClientHostVerificationDisabled())
            .encoder(new GsonEncoder(ModelUtils.GSON))
            .target(Login.class, loginURL);

    Response response = client.login(new AuthRequest(getUsername(), getPassword(), "LOCAL"));

    if (response.status() == OK.code()) {
        Collection<String> headers = response.headers().get(TOKEN_HEADER_NAME);
        return headers.toArray(new String[headers.size()])[0];
    } else {
        throw new TestFrameworkException(TestFrameworkException.Type.LoginFailed, "Exception while " +
                "logging into the cluster. Authentication service returned the following error: "
                + response);
    }
}
 
Example 3
Source Project: marathon-client   Source File: MarathonClient.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Exception decode(String methodKey, Response response) {
	if (response.status() >= 400 && response.status() < 500 ) {
		try {
			ErrorResponse parsed = ModelUtils.GSON.fromJson(response.body().asReader(), ErrorResponse.class);
			return new MarathonException(response.status(), response.reason(), parsed);
		} catch (IOException e) {
			// intentionally nothing
		}
	}
	return new MarathonException(response.status(), response.reason());
}
 
Example 4
Source Project: marathon-client   Source File: DCOSClient.java    License: Apache License 2.0 5 votes vote down vote up
private static DCOS buildInstance(String endpoint, Consumer<Feign.Builder> customize) {
    GsonDecoder decoder = new GsonDecoder(ModelUtils.GSON);
    GsonEncoder encoder = new GsonEncoder(ModelUtils.GSON);

    Feign.Builder builder = Feign.builder()
                                 .encoder(encoder)
                                 .decoder(decoder)
                                 .errorDecoder(new DCOSErrorDecoder());
    customize.accept(builder);
    builder.requestInterceptor(new DCOSAPIInterceptor());

    return builder.target(DCOS.class, endpoint);
}
 
Example 5
Source Project: spring-cloud-marathon   Source File: RibbonMarathonClient.java    License: MIT License 5 votes vote down vote up
public Marathon build() {
    if (null == listOfServers) {
        if (!StringUtils.isEmpty(token)) {
            return getInstanceWithTokenAuth(baseEndpoint, token);
        } else if (!StringUtils.isEmpty(username)) {
            return getInstanceWithBasicAuth(baseEndpoint, username, password);
        } else {
            return getInstance(baseEndpoint);
        }
    } else {
        setMarathonRibbonProperty("listOfServers", listOfServers);
        setMarathonRibbonProperty("OkToRetryOnAllOperations", Boolean.TRUE.toString());
        setMarathonRibbonProperty("MaxAutoRetriesNextServer", maxRetryCount);
        setMarathonRibbonProperty("ConnectTimeout", connectionTimeout);
        setMarathonRibbonProperty("ReadTimeout", readTimeout);

        Feign.Builder builder = Feign.builder()
                .client(RibbonClient.builder().lbClientFactory(new MarathonLBClientFactory()).build())
                .encoder(new GsonEncoder(ModelUtils.GSON))
                .decoder(new GsonDecoder(ModelUtils.GSON))
                .errorDecoder(new MarathonErrorDecoder());

        if (!StringUtils.isEmpty(token)) {
            builder.requestInterceptor(new TokenAuthRequestInterceptor(token));
        }
        else if (!StringUtils.isEmpty(username)) {
            builder.requestInterceptor(new BasicAuthRequestInterceptor(username,password));
        }

        builder.requestInterceptor(new MarathonHeadersInterceptor());

        return builder.target(Marathon.class, DEFAULT_MARATHON_ENDPOINT);
    }
}
 
Example 6
Source Project: pravega   Source File: AuthEnabledMarathonClient.java    License: Apache License 2.0 5 votes vote down vote up
private static Marathon getInstance(String endpoint, RequestInterceptor... interceptors) {
    Feign.Builder b = Feign.builder().client(LoginClient.getClientHostVerificationDisabled())
            .logger(new Logger.ErrorLogger())
            .logLevel(Logger.Level.BASIC)
            .encoder(new GsonEncoder(ModelUtils.GSON))
            .decoder(new GsonDecoder(ModelUtils.GSON))
            .errorDecoder(new MarathonErrorDecoder())
            //max wait period = 5 seconds ; max attempts = 5
            .retryer(new Retryer.Default(SECONDS.toMillis(1), SECONDS.toMillis(5), 5));
    if (interceptors != null) {
        b.requestInterceptors(asList(interceptors));
    }
    b.requestInterceptor(new MarathonHeadersInterceptor());
    return b.target(Marathon.class, endpoint);
}
 
Example 7
Source Project: pravega   Source File: MetronomeClient.java    License: Apache License 2.0 5 votes vote down vote up
public static Metronome getInstance(String endpoint, RequestInterceptor... interceptors) {
    Feign.Builder b = Feign.builder().client(LoginClient.getClientHostVerificationDisabled())
            .logger(new Logger.ErrorLogger())
            .logLevel(Logger.Level.BASIC)
            .encoder(new GsonEncoder(ModelUtils.GSON))
            .decoder(new GsonDecoder(ModelUtils.GSON))
            //max wait period = 5 seconds ; max attempts = 5
            .retryer(new Retryer.Default(SECONDS.toMillis(1), SECONDS.toMillis(5), 5))
            .errorDecoder(new MetronomeErrorDecoder());
    if (interceptors != null) {
        b.requestInterceptors(asList(interceptors));
    }
    b.requestInterceptor(new MetronomeHeadersInterceptor());
    return b.target(Metronome.class, endpoint);
}
 
Example 8
Source Project: marathon-client   Source File: HealthCheckResult.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public String toString() {
	return ModelUtils.toString(this);
}
 
Example 9
Source Project: marathon-client   Source File: GetAppVersionsResponse.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public String toString() {
    return ModelUtils.toString(this);
}
 
Example 10
Source Project: marathon-client   Source File: SecretSource.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public String toString() {
    return ModelUtils.toString(this);
}
 
Example 11
Source Project: marathon-client   Source File: Plugin.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public String toString() {
    return ModelUtils.toString(this);
}
 
Example 12
Source Project: marathon-client   Source File: Plugin.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public String toString() {
    return ModelUtils.toString(this);
}
 
Example 13
Source Project: marathon-client   Source File: ExternalVolume.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public String toString() {
    return ModelUtils.toString(this);
}
 
Example 14
Source Project: marathon-client   Source File: ExternalVolume.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public String toString() {
    return ModelUtils.toString(this);
}
 
Example 15
Source Project: marathon-client   Source File: ExternalVolume.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public String toString() {
    return ModelUtils.toString(this);
}
 
Example 16
Source Project: marathon-client   Source File: GetLeaderResponse.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public String toString() {
    return ModelUtils.toString(this);
}
 
Example 17
Source Project: marathon-client   Source File: UpgradeStrategy.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public String toString() {
    return ModelUtils.toString(this);
}
 
Example 18
Source Project: marathon-client   Source File: GetDeploymentsResponse.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public String toString() {
	return ModelUtils.toString(this);
}
 
Example 19
Source Project: marathon-client   Source File: GetAppResponse.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public String toString() {
	return ModelUtils.toString(this);
}
 
Example 20
Source Project: marathon-client   Source File: QueueResponse.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public String toString() {
    return ModelUtils.toString(this);
}
 
Example 21
Source Project: marathon-client   Source File: Deployment.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public String toString() {
	return ModelUtils.toString(this);
}
 
Example 22
Source Project: marathon-client   Source File: Deployment.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public String toString() {
	return ModelUtils.toString(this);
}
 
Example 23
Source Project: marathon-client   Source File: Deployment.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public String toString() {
	return ModelUtils.toString(this);
}
 
Example 24
Source Project: marathon-client   Source File: IpDiscoveryPort.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public String toString() {
    return ModelUtils.toString(this);
}
 
Example 25
Source Project: marathon-client   Source File: Docker.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public String toString() {
	return ModelUtils.toString(this);
}
 
Example 26
Source Project: marathon-client   Source File: GetAbdicateLeaderResponse.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public String toString() {
    return ModelUtils.toString(this);
}
 
Example 27
Source Project: marathon-client   Source File: GetAppNamespaceResponse.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public String toString() {
    return ModelUtils.toString(this);
}
 
Example 28
Source Project: marathon-client   Source File: Task.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public String toString() {
    return ModelUtils.toString(this);
}
 
Example 29
Source Project: marathon-client   Source File: AppVersionInfo.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public String toString() {
    return ModelUtils.toString(this);
}
 
Example 30
Source Project: marathon-client   Source File: LocalVolume.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public String toString() {
	return ModelUtils.toString(this);
}