Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDK-58/60: account creation/increase jersey timeout #54

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions src/main/java/com/qubole/qds/sdk/java/api/AccountApi.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* Copyright 2014- Qubole Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.qubole.qds.sdk.java.api;

import com.qubole.qds.sdk.java.entities.NewAccount;

public interface AccountApi
{
/**
* Account creation API
*
* @param configBuilder config values - use {@link #accountConfig()}
* @return new builder
*/
public InvokableBuilder<NewAccount> create(AccountConfigBuilder configBuilder);

/**
* Return a new account config builder. Can be used with
* apis such as {@link AccountApi#create(String, AccountConfigBuilder)}
*
* @return builder
*/
public AccountConfigBuilder accountConfig();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* Copyright 2014- Qubole Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.qubole.qds.sdk.java.api;

public interface AccountConfigBuilder
{
public AccountConfigBuilder name(String name);

public AccountConfigBuilder acc_key(String acc_key);

public AccountConfigBuilder secret(String secret);

public AccountConfigBuilder level(String level);

public AccountConfigBuilder compute_type(String compute_type);

public AccountConfigBuilder storage_type(String storage_type);

public AccountConfigBuilder aws_region(String aws_region);

public AccountConfigBuilder CacheQuotaSizeInGB(String CacheQuotaSizeInGB);

public AccountConfigBuilder use_previous_account_plan(boolean use_previous_account_plan);

public AccountConfigBuilder compute_access_key(String compute_access_key);

public AccountConfigBuilder compute_secret_key(String compute_secret_key);

public AccountConfigBuilder defloc(String defloc);
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class DefaultQdsConfiguration implements QdsConfiguration
public static final String API_VERSION = "v1.2";

private static final int DEFAULT_CONNECTION_TIMEOUT = (int) TimeUnit.SECONDS.toMillis(10);
private static final int DEFAULT_READ_TIMEOUT = (int) TimeUnit.SECONDS.toMillis(30);
private static final int DEFAULT_READ_TIMEOUT = (int) TimeUnit.SECONDS.toMillis(60);

/**
* @param apiToken your API token
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/com/qubole/qds/sdk/java/client/QdsClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.qubole.qds.sdk.java.client;

import com.qubole.qds.sdk.java.api.AccountApi;
import com.qubole.qds.sdk.java.api.ClusterApi;
import com.qubole.qds.sdk.java.api.CommandApi;
import com.qubole.qds.sdk.java.api.DbTapApi;
Expand Down Expand Up @@ -75,6 +76,13 @@ public interface QdsClient extends Closeable
*/
public SchedulerApi scheduler();

/**
* Return account api factory
*
* @return account factory
*/
public AccountApi account();

/**
* Low-level request invoker. Not normally used directly. Use the api factories instead.
*
Expand Down
45 changes: 45 additions & 0 deletions src/main/java/com/qubole/qds/sdk/java/details/AccountApiImpl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* Copyright 2014- Qubole Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.qubole.qds.sdk.java.details;

import com.qubole.qds.sdk.java.api.AccountApi;
import com.qubole.qds.sdk.java.api.AccountConfigBuilder;
import com.qubole.qds.sdk.java.api.InvokableBuilder;
import com.qubole.qds.sdk.java.client.QdsClient;
import com.qubole.qds.sdk.java.entities.NewAccount;

class AccountApiImpl implements AccountApi
{
private final QdsClient client;

AccountApiImpl(QdsClient client)
{
this.client = client;
}

@Override
public InvokableBuilder<NewAccount> create(AccountConfigBuilder configBuilder)
{
RequestDetails entity = new RequestDetails(configBuilder.toString(), RequestDetails.Method.POST);
return new GenericInvokableBuilderImpl<NewAccount>(client, entity, NewAccount.class, "account");
}

@Override
public AccountConfigBuilder accountConfig()
{
return new AccountConfigBuilderImpl();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
/**
* Copyright 2014- Qubole Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.qubole.qds.sdk.java.details;

import java.io.IOException;
import org.codehaus.jackson.node.ObjectNode;
import com.qubole.qds.sdk.java.api.AccountConfigBuilder;

public class AccountConfigBuilderImpl implements AccountConfigBuilder
{
private final ObjectNode node = QdsClientImpl.getMapper().createObjectNode();

@Override
public AccountConfigBuilder name(String name)
{
node.put("name", name);
return this;
}

@Override
public AccountConfigBuilder acc_key(String acc_key)
{
node.put("acc_key", acc_key);
return this;
}

@Override
public AccountConfigBuilder secret(String secret)
{
node.put("secret", secret);
return this;
}

@Override
public AccountConfigBuilder level(String level)
{
node.put("level", level);
return this;
}

@Override
public AccountConfigBuilder compute_type(String compute_type)
{
node.put("compute_type", compute_type);
return this;
}

@Override
public AccountConfigBuilder storage_type(String storage_type)
{
node.put("storage_type", storage_type);
return this;
}

@Override
public AccountConfigBuilder aws_region(String aws_region)
{
node.put("aws_region", aws_region);
return this;
}

@Override
public AccountConfigBuilder CacheQuotaSizeInGB(String CacheQuotaSizeInGB)
{
node.put("CacheQuotaSizeInGB", CacheQuotaSizeInGB);
return this;
}

@Override
public AccountConfigBuilder use_previous_account_plan(boolean use_previous_account_plan)
{
node.put("use_previous_account_plan", use_previous_account_plan);
return this;
}

@Override
public AccountConfigBuilder compute_access_key(String compute_access_key)
{
node.put("compute_access_key", compute_access_key);
return this;
}

@Override
public AccountConfigBuilder compute_secret_key(String compute_secret_key)
{
node.put("compute_secret_key", compute_secret_key);
return this;
}

@Override
public AccountConfigBuilder defloc(String defloc)
{
node.put("defloc", defloc);
return this;
}

public ObjectNode getNode()
{
ObjectNode clusterNode = QdsClientImpl.getMapper().createObjectNode();
clusterNode.put("account", node);
return clusterNode;
}

@Override
public String toString()
{
try
{
return QdsClientImpl.getMapper().writer().writeValueAsString(getNode());
}
catch (IOException e)
{
throw new RuntimeException("Could not serialize: " + node, e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
import com.qubole.qds.sdk.java.api.AccountApi;
import com.qubole.qds.sdk.java.api.ClusterApi;
import com.qubole.qds.sdk.java.api.CommandApi;
import com.qubole.qds.sdk.java.api.DbTapApi;
Expand All @@ -31,7 +32,6 @@
import org.codehaus.jackson.Version;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.map.module.SimpleModule;

import javax.ws.rs.client.AsyncInvoker;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.Entity;
Expand All @@ -56,6 +56,7 @@ public class QdsClientImpl implements QdsClient
private final DbTapApiImpl dbTapsApi;
private final ReportApiImpl reportApi;
private final SchedulerApiImpl schedulerApi;
private final AccountApiImpl accountApi;

private static final ObjectMapper MAPPER = new ObjectMapper();

Expand All @@ -75,6 +76,7 @@ public QdsClientImpl(QdsConfiguration configuration)
dbTapsApi = new DbTapApiImpl(this);
reportApi = new ReportApiImpl(this);
schedulerApi = new SchedulerApiImpl(this);
accountApi = new AccountApiImpl(this);

// register the deserialization handler for composite command
SimpleModule module =
Expand Down Expand Up @@ -121,6 +123,11 @@ public SchedulerApi scheduler()
return schedulerApi;
}

@Override
public AccountApi account() {
return accountApi;
}

@Override
public <T> Future<T> invokeRequest(ForPage forPage, RequestDetails requestDetails, Class<T> responseType, String... additionalPaths)
{
Expand Down
Loading