mesosphere.client.common.ModelUtils Java Examples

The following examples show how to use mesosphere.client.common.ModelUtils. 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: MarathonClient.java    From marathon-client with Apache License 2.0 7 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 File: LoginClient.java    From pravega with 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 File: MarathonClient.java    From marathon-client with 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 File: AuthEnabledMarathonClient.java    From pravega with 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 #5
Source File: RibbonMarathonClient.java    From spring-cloud-marathon with 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 File: DCOSClient.java    From marathon-client with 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 #7
Source File: MetronomeClient.java    From pravega with 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 File: App.java    From marathon-client with Apache License 2.0 4 votes vote down vote up
@Override
public String toString() {
	return ModelUtils.toString(this);
}
 
Example #9
Source File: HealthCheckResult.java    From marathon-client with Apache License 2.0 4 votes vote down vote up
@Override
public String toString() {
	return ModelUtils.toString(this);
}
 
Example #10
Source File: DeleteAppTasksResponse.java    From marathon-client with Apache License 2.0 4 votes vote down vote up
@Override
public String toString() {
	return ModelUtils.toString(this);
}
 
Example #11
Source File: ReadinessCheck.java    From marathon-client with Apache License 2.0 4 votes vote down vote up
@Override
public String toString() {
	return ModelUtils.toString(this);
}
 
Example #12
Source File: GetGroupsResponse.java    From marathon-client with Apache License 2.0 4 votes vote down vote up
@Override
public String toString() {
	return ModelUtils.toString(this);
}
 
Example #13
Source File: TaskFailure.java    From marathon-client with Apache License 2.0 4 votes vote down vote up
@Override
public String toString() {
	return ModelUtils.toString(this);
}
 
Example #14
Source File: Plugin.java    From marathon-client with Apache License 2.0 4 votes vote down vote up
@Override
public String toString() {
    return ModelUtils.toString(this);
}
 
Example #15
Source File: DCOSAuthToken.java    From marathon-client with Apache License 2.0 4 votes vote down vote up
@Override
public String toString() {
    return ModelUtils.toString(this);
}
 
Example #16
Source File: DCOSAuthCredentials.java    From marathon-client with Apache License 2.0 4 votes vote down vote up
@Override
public String toString() {
    return ModelUtils.toString(this);
}
 
Example #17
Source File: AuthenticateResponse.java    From marathon-client with Apache License 2.0 4 votes vote down vote up
@Override
public String toString() {
    return ModelUtils.toString(this);
}
 
Example #18
Source File: GetAppVersionsResponse.java    From marathon-client with Apache License 2.0 4 votes vote down vote up
@Override
public String toString() {
    return ModelUtils.toString(this);
}
 
Example #19
Source File: App.java    From marathon-client with Apache License 2.0 4 votes vote down vote up
@Override
public String toString() {
	return ModelUtils.toString(this);
}
 
Example #20
Source File: GetEventSubscriptionRegisterResponse.java    From marathon-client with Apache License 2.0 4 votes vote down vote up
@Override
public String toString() {
    return ModelUtils.toString(this);
}
 
Example #21
Source File: Result.java    From marathon-client with Apache License 2.0 4 votes vote down vote up
@Override
public String toString() {
	return ModelUtils.toString(this);
}
 
Example #22
Source File: Network.java    From marathon-client with Apache License 2.0 4 votes vote down vote up
@Override
public String toString() {
	return ModelUtils.toString(this);
}
 
Example #23
Source File: GetPluginsResponse.java    From marathon-client with Apache License 2.0 4 votes vote down vote up
@Override
public String toString() {
    return ModelUtils.toString(this);
}
 
Example #24
Source File: GetServerInfoResponse.java    From marathon-client with Apache License 2.0 4 votes vote down vote up
@Override
public String toString() {
    return ModelUtils.toString(this);
}
 
Example #25
Source File: GetServerInfoResponse.java    From marathon-client with Apache License 2.0 4 votes vote down vote up
@Override
public String toString() {
    return ModelUtils.toString(this);
}
 
Example #26
Source File: GetServerInfoResponse.java    From marathon-client with Apache License 2.0 4 votes vote down vote up
@Override
public String toString() {
    return ModelUtils.toString(this);
}
 
Example #27
Source File: GetServerInfoResponse.java    From marathon-client with Apache License 2.0 4 votes vote down vote up
@Override
public String toString() {
    return ModelUtils.toString(this);
}
 
Example #28
Source File: GetServerInfoResponse.java    From marathon-client with Apache License 2.0 4 votes vote down vote up
@Override
public String toString() {
    return ModelUtils.toString(this);
}
 
Example #29
Source File: ExternalVolume.java    From marathon-client with Apache License 2.0 4 votes vote down vote up
@Override
public String toString() {
    return ModelUtils.toString(this);
}
 
Example #30
Source File: IpAddress.java    From marathon-client with Apache License 2.0 4 votes vote down vote up
@Override
public String toString() {
    return ModelUtils.toString(this);
}