From bb6b10caa5a9d64b2875de00279e9c7ba05e8c9c Mon Sep 17 00:00:00 2001 From: Abhishek Srivastava Date: Tue, 17 Nov 2015 15:57:09 +0530 Subject: [PATCH 1/2] SDK-58/60: account creation/increase jersey timeout --- .../qubole/qds/sdk/java/api/AccountApi.java | 37 ++++ .../sdk/java/api/AccountConfigBuilder.java | 43 +++++ .../java/client/DefaultQdsConfiguration.java | 2 +- .../qubole/qds/sdk/java/client/QdsClient.java | 8 + .../qds/sdk/java/details/AccountApiImpl.java | 45 +++++ .../details/AccountConfigBuilderImpl.java | 132 +++++++++++++ .../qds/sdk/java/details/QdsClientImpl.java | 12 +- .../qds/sdk/java/entities/NewAccount.java | 175 ++++++++++++++++++ .../qds/sdk/java/details/MockClient.java | 9 + 9 files changed, 461 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/qubole/qds/sdk/java/api/AccountApi.java create mode 100644 src/main/java/com/qubole/qds/sdk/java/api/AccountConfigBuilder.java create mode 100644 src/main/java/com/qubole/qds/sdk/java/details/AccountApiImpl.java create mode 100644 src/main/java/com/qubole/qds/sdk/java/details/AccountConfigBuilderImpl.java create mode 100644 src/main/java/com/qubole/qds/sdk/java/entities/NewAccount.java diff --git a/src/main/java/com/qubole/qds/sdk/java/api/AccountApi.java b/src/main/java/com/qubole/qds/sdk/java/api/AccountApi.java new file mode 100644 index 00000000..0a6080f7 --- /dev/null +++ b/src/main/java/com/qubole/qds/sdk/java/api/AccountApi.java @@ -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 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(); +} diff --git a/src/main/java/com/qubole/qds/sdk/java/api/AccountConfigBuilder.java b/src/main/java/com/qubole/qds/sdk/java/api/AccountConfigBuilder.java new file mode 100644 index 00000000..a200072d --- /dev/null +++ b/src/main/java/com/qubole/qds/sdk/java/api/AccountConfigBuilder.java @@ -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); +} diff --git a/src/main/java/com/qubole/qds/sdk/java/client/DefaultQdsConfiguration.java b/src/main/java/com/qubole/qds/sdk/java/client/DefaultQdsConfiguration.java index ad228998..e13eb3c3 100644 --- a/src/main/java/com/qubole/qds/sdk/java/client/DefaultQdsConfiguration.java +++ b/src/main/java/com/qubole/qds/sdk/java/client/DefaultQdsConfiguration.java @@ -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 diff --git a/src/main/java/com/qubole/qds/sdk/java/client/QdsClient.java b/src/main/java/com/qubole/qds/sdk/java/client/QdsClient.java index 7356f9d7..d28d9665 100644 --- a/src/main/java/com/qubole/qds/sdk/java/client/QdsClient.java +++ b/src/main/java/com/qubole/qds/sdk/java/client/QdsClient.java @@ -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; @@ -74,6 +75,13 @@ public interface QdsClient extends Closeable * @return scheduler factory */ 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. diff --git a/src/main/java/com/qubole/qds/sdk/java/details/AccountApiImpl.java b/src/main/java/com/qubole/qds/sdk/java/details/AccountApiImpl.java new file mode 100644 index 00000000..1ac9bce1 --- /dev/null +++ b/src/main/java/com/qubole/qds/sdk/java/details/AccountApiImpl.java @@ -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 create(AccountConfigBuilder configBuilder) + { + RequestDetails entity = new RequestDetails(configBuilder.toString(), RequestDetails.Method.POST); + return new GenericInvokableBuilderImpl(client, entity, NewAccount.class, "account"); + } + + @Override + public AccountConfigBuilder accountConfig() + { + return new AccountConfigBuilderImpl(); + } +} diff --git a/src/main/java/com/qubole/qds/sdk/java/details/AccountConfigBuilderImpl.java b/src/main/java/com/qubole/qds/sdk/java/details/AccountConfigBuilderImpl.java new file mode 100644 index 00000000..b1fd2217 --- /dev/null +++ b/src/main/java/com/qubole/qds/sdk/java/details/AccountConfigBuilderImpl.java @@ -0,0 +1,132 @@ +/** + * 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); + } + } + +} diff --git a/src/main/java/com/qubole/qds/sdk/java/details/QdsClientImpl.java b/src/main/java/com/qubole/qds/sdk/java/details/QdsClientImpl.java index 3ac9c5ad..686ec4d6 100644 --- a/src/main/java/com/qubole/qds/sdk/java/details/QdsClientImpl.java +++ b/src/main/java/com/qubole/qds/sdk/java/details/QdsClientImpl.java @@ -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; @@ -28,6 +29,7 @@ import com.qubole.qds.sdk.java.client.retry.RetryConnector; import com.qubole.qds.sdk.java.entities.SubCommands; import com.qubole.qds.sdk.java.entities.SubCommandsDeserializer; + import org.codehaus.jackson.Version; import org.codehaus.jackson.map.ObjectMapper; import org.codehaus.jackson.map.module.SimpleModule; @@ -40,6 +42,7 @@ import javax.ws.rs.client.WebTarget; import javax.ws.rs.core.GenericType; import javax.ws.rs.core.MediaType; + import java.util.Map; import java.util.concurrent.Future; import java.util.concurrent.atomic.AtomicBoolean; @@ -56,6 +59,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(); @@ -75,7 +79,8 @@ 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 = new SimpleModule("CommandResponseDeserializerModule", @@ -120,6 +125,11 @@ public SchedulerApi scheduler() { return schedulerApi; } + + @Override + public AccountApi account() { + return accountApi; + } @Override public Future invokeRequest(ForPage forPage, RequestDetails requestDetails, Class responseType, String... additionalPaths) diff --git a/src/main/java/com/qubole/qds/sdk/java/entities/NewAccount.java b/src/main/java/com/qubole/qds/sdk/java/entities/NewAccount.java new file mode 100644 index 00000000..0e422648 --- /dev/null +++ b/src/main/java/com/qubole/qds/sdk/java/entities/NewAccount.java @@ -0,0 +1,175 @@ +/** + * 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.entities; + +import org.codehaus.jackson.annotate.JsonIgnoreProperties; + +@JsonIgnoreProperties(ignoreUnknown = true) +public class NewAccount +{ + private long account_id; + private String authentication_token; + private long capabilities; + private String created_at; + private boolean disabled; + private long id; + private boolean is_admin; + private boolean is_default; + private String setting_id; + private String setting_type; + private String updated_at; + private long user_id; + + NewAccount() + { + } + + NewAccount(long account_id, String authentication_token, long capabilities, String created_at, boolean disabled, long id, boolean is_admin, boolean is_default, String setting_id, String setting_type, String updated_at, long user_id) + { + this.account_id = account_id; + this.authentication_token = authentication_token; + this.capabilities = capabilities; + this.created_at = created_at; + this.disabled = disabled; + this.id = id; + this.is_admin = is_admin; + this.is_default = is_default; + this.setting_id = setting_id; + this.setting_type = setting_type; + this.updated_at = updated_at; + this.user_id = user_id; + } + + public long getAccount_id() + { + return account_id; + } + + public void setAccount_id(long account_id) + { + this.account_id = account_id; + } + + public String getAuthentication_token() + { + return authentication_token; + } + + public void setAuthentication_token(String authentication_token) + { + this.authentication_token = authentication_token; + } + + public long getCapabilities() + { + return capabilities; + } + + public void setCapabilities(long capabilities) + { + this.capabilities = capabilities; + } + + public String getCreated_at() + { + return created_at; + } + + public void setCreated_at(String created_at) + { + this.created_at = created_at; + } + + public boolean getDisabled() + { + return disabled; + } + + public void setDisabled(boolean disabled) + { + this.disabled = disabled; + } + + public long getId() + { + return id; + } + + public void setId(long id) + { + this.id = id; + } + + public boolean getIs_admin() + { + return is_admin; + } + + public void setIs_admin(boolean is_admin) + { + this.is_admin = is_admin; + } + + public boolean getIs_default() + { + return is_default; + } + + public void setIs_default(boolean is_default) + { + this.is_default = is_default; + } + + public String getSetting_id() + { + return setting_id; + } + + public void setSetting_id(String setting_id) + { + this.setting_id = setting_id; + } + + public String getSetting_type() + { + return setting_type; + } + + public void setSetting_type(String setting_type) + { + this.setting_type = setting_type; + } + + public String getUpdated_at() + { + return updated_at; + } + + public void setUpdated_at(String updated_at) + { + this.updated_at = updated_at; + } + + public long getUser_id() + { + return user_id; + } + + public void setUser_id(long user_id) + { + this.user_id = user_id; + } +} diff --git a/src/test/java/com/qubole/qds/sdk/java/details/MockClient.java b/src/test/java/com/qubole/qds/sdk/java/details/MockClient.java index 81a4b92c..1de4f9da 100644 --- a/src/test/java/com/qubole/qds/sdk/java/details/MockClient.java +++ b/src/test/java/com/qubole/qds/sdk/java/details/MockClient.java @@ -16,6 +16,7 @@ package com.qubole.qds.sdk.java.details; import com.google.common.collect.Queues; +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; @@ -23,8 +24,10 @@ import com.qubole.qds.sdk.java.api.ReportApi; import com.qubole.qds.sdk.java.api.SchedulerApi; import com.qubole.qds.sdk.java.client.QdsClient; + import javax.ws.rs.client.InvocationCallback; import javax.ws.rs.core.GenericType; + import java.util.concurrent.BlockingQueue; import java.util.concurrent.Future; @@ -147,6 +150,12 @@ public SchedulerApi scheduler() { return new SchedulerApiImpl(this); } + + @Override + public AccountApi account() + { + return new AccountApiImpl(this); + } @Override public void close() From d1ca1a94a01d6f9f6e56847804bba09c0244f897 Mon Sep 17 00:00:00 2001 From: Abhishek Srivastava Date: Tue, 19 Jan 2016 11:37:35 +0530 Subject: [PATCH 2/2] spacing fixes --- .../qubole/qds/sdk/java/details/AccountConfigBuilderImpl.java | 4 +--- .../java/com/qubole/qds/sdk/java/details/QdsClientImpl.java | 3 --- .../java/com/qubole/qds/sdk/java/entities/NewAccount.java | 1 + src/test/java/com/qubole/qds/sdk/java/details/MockClient.java | 2 -- 4 files changed, 2 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/qubole/qds/sdk/java/details/AccountConfigBuilderImpl.java b/src/main/java/com/qubole/qds/sdk/java/details/AccountConfigBuilderImpl.java index b1fd2217..1321950e 100644 --- a/src/main/java/com/qubole/qds/sdk/java/details/AccountConfigBuilderImpl.java +++ b/src/main/java/com/qubole/qds/sdk/java/details/AccountConfigBuilderImpl.java @@ -16,9 +16,7 @@ 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 @@ -128,5 +126,5 @@ public String toString() throw new RuntimeException("Could not serialize: " + node, e); } } - } + diff --git a/src/main/java/com/qubole/qds/sdk/java/details/QdsClientImpl.java b/src/main/java/com/qubole/qds/sdk/java/details/QdsClientImpl.java index 686ec4d6..23c458bc 100644 --- a/src/main/java/com/qubole/qds/sdk/java/details/QdsClientImpl.java +++ b/src/main/java/com/qubole/qds/sdk/java/details/QdsClientImpl.java @@ -29,11 +29,9 @@ import com.qubole.qds.sdk.java.client.retry.RetryConnector; import com.qubole.qds.sdk.java.entities.SubCommands; import com.qubole.qds.sdk.java.entities.SubCommandsDeserializer; - 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; @@ -42,7 +40,6 @@ import javax.ws.rs.client.WebTarget; import javax.ws.rs.core.GenericType; import javax.ws.rs.core.MediaType; - import java.util.Map; import java.util.concurrent.Future; import java.util.concurrent.atomic.AtomicBoolean; diff --git a/src/main/java/com/qubole/qds/sdk/java/entities/NewAccount.java b/src/main/java/com/qubole/qds/sdk/java/entities/NewAccount.java index 0e422648..b7f41d73 100644 --- a/src/main/java/com/qubole/qds/sdk/java/entities/NewAccount.java +++ b/src/main/java/com/qubole/qds/sdk/java/entities/NewAccount.java @@ -173,3 +173,4 @@ public void setUser_id(long user_id) this.user_id = user_id; } } + diff --git a/src/test/java/com/qubole/qds/sdk/java/details/MockClient.java b/src/test/java/com/qubole/qds/sdk/java/details/MockClient.java index 1de4f9da..79a236fc 100644 --- a/src/test/java/com/qubole/qds/sdk/java/details/MockClient.java +++ b/src/test/java/com/qubole/qds/sdk/java/details/MockClient.java @@ -24,10 +24,8 @@ import com.qubole.qds.sdk.java.api.ReportApi; import com.qubole.qds.sdk.java.api.SchedulerApi; import com.qubole.qds.sdk.java.client.QdsClient; - import javax.ws.rs.client.InvocationCallback; import javax.ws.rs.core.GenericType; - import java.util.concurrent.BlockingQueue; import java.util.concurrent.Future;