You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dlab.apache.org by bh...@apache.org on 2019/04/03 12:59:06 UTC

[incubator-dlab] branch bugfix-DLAB-574 created (now 2f79cd9)

This is an automated email from the ASF dual-hosted git repository.

bhliva pushed a change to branch bugfix-DLAB-574
in repository https://gitbox.apache.org/repos/asf/incubator-dlab.git.


      at 2f79cd9  DLAB-574 removed azure_client_id param from docker requests

This branch includes the following new commits:

     new 2f79cd9  DLAB-574 removed azure_client_id param from docker requests

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@dlab.apache.org
For additional commands, e-mail: commits-help@dlab.apache.org


[incubator-dlab] 01/01: DLAB-574 removed azure_client_id param from docker requests

Posted by bh...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

bhliva pushed a commit to branch bugfix-DLAB-574
in repository https://gitbox.apache.org/repos/asf/incubator-dlab.git

commit 2f79cd972af84b107e2858461722792f6a274f5b
Author: bhliva <bo...@epam.com>
AuthorDate: Wed Apr 3 15:58:54 2019 +0300

    DLAB-574 removed azure_client_id param from docker requests
---
 .../SparkComputationalCreateAzure.java             |    8 -
 .../exploratory/ExploratoryActionStartAzure.java   |   76 +-
 .../azure/exploratory/ExploratoryCreateAzure.java  |   16 -
 .../epam/dlab/backendapi/util/RequestBuilder.java  | 1055 ++++++++++----------
 4 files changed, 556 insertions(+), 599 deletions(-)

diff --git a/services/dlab-model/src/main/java/com/epam/dlab/dto/azure/computational/SparkComputationalCreateAzure.java b/services/dlab-model/src/main/java/com/epam/dlab/dto/azure/computational/SparkComputationalCreateAzure.java
index 89c1a5a..1bc79fc 100644
--- a/services/dlab-model/src/main/java/com/epam/dlab/dto/azure/computational/SparkComputationalCreateAzure.java
+++ b/services/dlab-model/src/main/java/com/epam/dlab/dto/azure/computational/SparkComputationalCreateAzure.java
@@ -33,8 +33,6 @@ public class SparkComputationalCreateAzure extends ComputationalBase<SparkComput
 	private String dataEngineSlaveSize;
 	@JsonProperty("azure_dataengine_master_size")
 	private String dataEngineMasterSize;
-	@JsonProperty("azure_client_id")
-	private String azureClientId;
 	@JsonProperty("azure_datalake_enable")
 	private String azureDataLakeEnabled;
 	@JsonProperty("azure_user_refresh_token")
@@ -57,11 +55,6 @@ public class SparkComputationalCreateAzure extends ComputationalBase<SparkComput
 		return this;
 	}
 
-	public SparkComputationalCreateAzure withAzureClientId(String azureClientId) {
-		this.azureClientId = azureClientId;
-		return this;
-	}
-
 	public SparkComputationalCreateAzure withAzureDataLakeEnabled(String azureDataLakeEnabled) {
 		this.azureDataLakeEnabled = azureDataLakeEnabled;
 		return this;
@@ -83,7 +76,6 @@ public class SparkComputationalCreateAzure extends ComputationalBase<SparkComput
 				.add("dataEngineInstanceCount", dataEngineInstanceCount)
 				.add("dataEngineSlaveSize", dataEngineSlaveSize)
 				.add("dataEngineMasterSize", dataEngineMasterSize)
-				.add("azureClientId", azureClientId != null ? "***" : null)
 				.add("azureDataLakeEnabled", azureDataLakeEnabled)
 				.add("azureUserRefreshToken", azureUserRefreshToken != null ? "***" : null);
 	}
diff --git a/services/dlab-model/src/main/java/com/epam/dlab/dto/azure/exploratory/ExploratoryActionStartAzure.java b/services/dlab-model/src/main/java/com/epam/dlab/dto/azure/exploratory/ExploratoryActionStartAzure.java
index 5869b90..48c314a 100644
--- a/services/dlab-model/src/main/java/com/epam/dlab/dto/azure/exploratory/ExploratoryActionStartAzure.java
+++ b/services/dlab-model/src/main/java/com/epam/dlab/dto/azure/exploratory/ExploratoryActionStartAzure.java
@@ -24,57 +24,41 @@ import com.fasterxml.jackson.annotation.JsonProperty;
 import com.google.common.base.MoreObjects;
 
 public class ExploratoryActionStartAzure extends ExploratoryGitCredsUpdateDTO {
-    @JsonProperty("azure_client_id")
-    private String azureClientId;
-    @JsonProperty("azure_datalake_enable")
-    private String azureDataLakeEnabled;
-    @JsonProperty("azure_user_refresh_token")
-    private String azureUserRefreshToken;
+	@JsonProperty("azure_datalake_enable")
+	private String azureDataLakeEnabled;
+	@JsonProperty("azure_user_refresh_token")
+	private String azureUserRefreshToken;
 
-    public String getAzureClientId() {
-        return azureClientId;
-    }
+	public String getAzureDataLakeEnabled() {
+		return azureDataLakeEnabled;
+	}
 
-    public void setAzureClientId(String azureClientId) {
-        this.azureClientId = azureClientId;
-    }
+	public void setAzureDataLakeEnabled(String azureDataLakeEnabled) {
+		this.azureDataLakeEnabled = azureDataLakeEnabled;
+	}
 
-    public String getAzureDataLakeEnabled() {
-        return azureDataLakeEnabled;
-    }
+	public String getAzureUserRefreshToken() {
+		return azureUserRefreshToken;
+	}
 
-    public void setAzureDataLakeEnabled(String azureDataLakeEnabled) {
-        this.azureDataLakeEnabled = azureDataLakeEnabled;
-    }
+	public void setAzureUserRefreshToken(String azureUserRefreshToken) {
+		this.azureUserRefreshToken = azureUserRefreshToken;
+	}
 
-    public String getAzureUserRefreshToken() {
-        return azureUserRefreshToken;
-    }
+	public ExploratoryActionStartAzure withAzureDataLakeEnabled(String azureDataLakeEnabled) {
+		setAzureDataLakeEnabled(azureDataLakeEnabled);
+		return this;
+	}
 
-    public void setAzureUserRefreshToken(String azureUserRefreshToken) {
-        this.azureUserRefreshToken = azureUserRefreshToken;
-    }
+	public ExploratoryActionStartAzure withAzureUserRefreshToken(String azureUserRefreshToken) {
+		setAzureUserRefreshToken(azureUserRefreshToken);
+		return this;
+	}
 
-    public ExploratoryActionStartAzure withAzureClientId(String azureClientId) {
-        setAzureClientId(azureClientId);
-        return this;
-    }
-
-    public ExploratoryActionStartAzure withAzureDataLakeEnabled(String azureDataLakeEnabled) {
-        setAzureDataLakeEnabled(azureDataLakeEnabled);
-        return this;
-    }
-
-    public ExploratoryActionStartAzure withAzureUserRefreshToken(String azureUserRefreshToken) {
-        setAzureUserRefreshToken(azureUserRefreshToken);
-        return this;
-    }
-
-    @Override
-    public MoreObjects.ToStringHelper toStringHelper(Object self) {
-        return super.toStringHelper(self)
-                .add("azureClientId", azureClientId != null ? "***" : null)
-                .add("azureDataLakeEnabled", azureDataLakeEnabled)
-                .add("azureUserRefreshToken", azureUserRefreshToken != null ? "***" : null);
-    }
+	@Override
+	public MoreObjects.ToStringHelper toStringHelper(Object self) {
+		return super.toStringHelper(self)
+				.add("azureDataLakeEnabled", azureDataLakeEnabled)
+				.add("azureUserRefreshToken", azureUserRefreshToken != null ? "***" : null);
+	}
 }
diff --git a/services/dlab-model/src/main/java/com/epam/dlab/dto/azure/exploratory/ExploratoryCreateAzure.java b/services/dlab-model/src/main/java/com/epam/dlab/dto/azure/exploratory/ExploratoryCreateAzure.java
index 371c316..bb2b443 100644
--- a/services/dlab-model/src/main/java/com/epam/dlab/dto/azure/exploratory/ExploratoryCreateAzure.java
+++ b/services/dlab-model/src/main/java/com/epam/dlab/dto/azure/exploratory/ExploratoryCreateAzure.java
@@ -26,8 +26,6 @@ import com.google.common.base.MoreObjects;
 public class ExploratoryCreateAzure extends ExploratoryCreateDTO<ExploratoryCreateAzure> {
     @JsonProperty("azure_notebook_instance_size")
     private String notebookInstanceType;
-    @JsonProperty("azure_client_id")
-    private String azureClientId;
     @JsonProperty("azure_datalake_enable")
     private String azureDataLakeEnabled;
     @JsonProperty("azure_user_refresh_token")
@@ -41,14 +39,6 @@ public class ExploratoryCreateAzure extends ExploratoryCreateDTO<ExploratoryCrea
         this.notebookInstanceType = notebookInstanceType;
     }
 
-    public String getAzureClientId() {
-        return azureClientId;
-    }
-
-    public void setAzureClientId(String azureClientId) {
-        this.azureClientId = azureClientId;
-    }
-
     public String getAzureDataLakeEnabled() {
         return azureDataLakeEnabled;
     }
@@ -70,11 +60,6 @@ public class ExploratoryCreateAzure extends ExploratoryCreateDTO<ExploratoryCrea
         return this;
     }
 
-    public ExploratoryCreateAzure withAzureClientId(String azureClientId) {
-        setAzureClientId(azureClientId);
-        return this;
-    }
-
     public ExploratoryCreateAzure withAzureDataLakeEnabled(String azureDataLakeEnabled) {
         setAzureDataLakeEnabled(azureDataLakeEnabled);
         return this;
@@ -89,7 +74,6 @@ public class ExploratoryCreateAzure extends ExploratoryCreateDTO<ExploratoryCrea
     public MoreObjects.ToStringHelper toStringHelper(Object self) {
         return super.toStringHelper(self)
                 .add("notebookInstanceType", notebookInstanceType)
-                .add("azureClientId", azureClientId != null ? "***" : null)
                 .add("azureDataLakeEnabled", azureDataLakeEnabled)
                 .add("azureUserRefreshToken", azureUserRefreshToken != null ? "***" : null);
     }
diff --git a/services/self-service/src/main/java/com/epam/dlab/backendapi/util/RequestBuilder.java b/services/self-service/src/main/java/com/epam/dlab/backendapi/util/RequestBuilder.java
index aaad7d1..3fb600e 100644
--- a/services/self-service/src/main/java/com/epam/dlab/backendapi/util/RequestBuilder.java
+++ b/services/self-service/src/main/java/com/epam/dlab/backendapi/util/RequestBuilder.java
@@ -74,535 +74,532 @@ import static com.epam.dlab.cloud.CloudProvider.*;
 
 @Singleton
 public class RequestBuilder {
-    private static final String UNSUPPORTED_CLOUD_PROVIDER_MESSAGE = "Unsupported cloud provider ";
-    private static final String AZURE_REFRESH_TOKEN_KEY = "refresh_token";
-
-    @Inject
-    private SelfServiceApplicationConfiguration configuration;
-    @Inject
-    private SettingsDAO settingsDAO;
-
-    private CloudSettings cloudSettings(UserInfo userInfo) {
-        switch (cloudProvider()) {
-            case AWS:
-                return AwsCloudSettings.builder()
-                        .awsRegion(settingsDAO.getAwsRegion())
-                        .awsSecurityGroupIds(settingsDAO.getAwsSecurityGroups())
-                        .awsSubnetId(settingsDAO.getAwsSubnetId())
-                        .awsVpcId(settingsDAO.getAwsVpcId())
-                        .confTagResourceId(settingsDAO.getConfTagResourceId())
-                        .awsNotebookSubnetId(settingsDAO.getAwsNotebookSubnetId())
-                        .awsNotebookVpcId(settingsDAO.getAwsNotebookVpcId())
-                        .awsIamUser(userInfo.getName()).build();
-            case AZURE:
-                return AzureCloudSettings.builder()
-                        .azureRegion(settingsDAO.getAzureRegion())
-                        .azureResourceGroupName(settingsDAO.getAzureResourceGroupName())
-                        .azureSecurityGroupName(settingsDAO.getAzureSecurityGroupName())
-                        .azureSubnetName(settingsDAO.getAzureSubnetName())
-                        .azureVpcName(settingsDAO.getAzureVpcName())
-                        .azureIamUser(userInfo.getName()).build();
-            case GCP:
-                return GcpCloudSettings.builder().gcpIamUser(userInfo.getName()).build();
-            default:
-                throw new IllegalArgumentException(UNSUPPORTED_CLOUD_PROVIDER_MESSAGE + cloudProvider());
-        }
-    }
-
-    @SuppressWarnings("unchecked")
-    private <T extends ResourceBaseDTO<?>> T newResourceBaseDTO(UserInfo userInfo, Class<T> resourceClass) {
-        try {
-            return (T) resourceClass.newInstance()
-                    .withEdgeUserName(getEdgeUserName(userInfo))
-                    .withCloudSettings(cloudSettings(userInfo));
-        } catch (Exception e) {
-            throw new DlabException("Cannot create instance of resource class " + resourceClass.getName() + ". " +
-                    e.getLocalizedMessage(), e);
-        }
-    }
-
-    private String getEdgeUserName(UserInfo userInfo) {
-        String edgeUser = UsernameUtils.replaceWhitespaces(userInfo.getSimpleName());
-        switch (cloudProvider()) {
-            case GCP:
-                return adjustUserName(configuration.getMaxUserNameLength(), edgeUser);
-            case AWS:
-            case AZURE:
-                return edgeUser;
-            default:
-                throw new DlabException(UNSUPPORTED_CLOUD_PROVIDER_MESSAGE + cloudProvider());
-        }
-    }
-
-    private String adjustUserName(int maxLength, String userName) {
-        return userName.length() > maxLength ?
-                UUID.nameUUIDFromBytes(userName.getBytes()).toString().substring(0, maxLength) : userName;
-    }
-
-    @SuppressWarnings("unchecked")
-    private <T extends ResourceSysBaseDTO<?>> T newResourceSysBaseDTO(UserInfo userInfo, Class<T> resourceClass) {
-        T resource = newResourceBaseDTO(userInfo, resourceClass);
-        return (T) resource
-                .withServiceBaseName(settingsDAO.getServiceBaseName())
-                .withConfOsFamily(settingsDAO.getConfOsFamily());
-    }
-
-    @SuppressWarnings("unchecked")
-    public UploadFile newEdgeKeyUpload(UserInfo userInfo, String content) {
-
-        switch (cloudProvider()) {
-            case AWS:
-                EdgeCreateAws edgeCreateAws = newResourceSysBaseDTO(userInfo, EdgeCreateAws.class);
-                UploadFileAws uploadFileAws = new UploadFileAws();
-                uploadFileAws.setEdge(edgeCreateAws);
-                uploadFileAws.setContent(content);
-
-                return uploadFileAws;
-
-            case AZURE:
-                EdgeCreateAzure edgeCreateAzure = newResourceSysBaseDTO(userInfo, EdgeCreateAzure.class)
-                        .withAzureDataLakeEnable(Boolean.toString(settingsDAO.isAzureDataLakeEnabled()));
-
-                UploadFileAzure uploadFileAzure = new UploadFileAzure();
-                uploadFileAzure.setEdge(edgeCreateAzure);
-                uploadFileAzure.setContent(content);
-
-                return uploadFileAzure;
-
-            case GCP:
-                return new UploadFileGcp(newResourceSysBaseDTO(userInfo, EdgeCreateGcp.class), content);
-            default:
-                throw new IllegalArgumentException(UNSUPPORTED_CLOUD_PROVIDER_MESSAGE + cloudProvider());
-        }
-    }
-
-    public ReuploadKeyDTO newKeyReupload(UserInfo userInfo, String id, String content, List<ResourceData> resources) {
-        return newResourceSysBaseDTO(userInfo, ReuploadKeyDTO.class)
-                .withId(id)
-                .withContent(content)
-                .withResources(resources);
-    }
-
-    @SuppressWarnings("unchecked")
-    public <T extends ResourceSysBaseDTO<?>> T newEdgeAction(UserInfo userInfo) {
-        checkInappropriateCloudProviderOrElseThrowException();
-        return (T) newResourceSysBaseDTO(userInfo, ResourceSysBaseDTO.class);
-    }
-
-    public UserEnvironmentResources newUserEnvironmentStatus(UserInfo userInfo) {
-        checkInappropriateCloudProviderOrElseThrowException();
-        return newResourceSysBaseDTO(userInfo, UserEnvironmentResources.class);
-    }
-
-    @SuppressWarnings("unchecked")
-    public <T extends ExploratoryCreateDTO<T>> T newExploratoryCreate(Exploratory exploratory, UserInfo userInfo,
-                                                                      ExploratoryGitCredsDTO exploratoryGitCredsDTO) {
-
-        T exploratoryCreate;
-
-        switch (cloudProvider()) {
-            case AWS:
-                exploratoryCreate = (T) newResourceSysBaseDTO(userInfo, ExploratoryCreateAws.class)
-                        .withNotebookInstanceType(exploratory.getShape());
-                break;
-            case AZURE:
-                exploratoryCreate = (T) newResourceSysBaseDTO(userInfo, ExploratoryCreateAzure.class)
-                        .withNotebookInstanceSize(exploratory.getShape());
-                if (settingsDAO.isAzureDataLakeEnabled()) {
-                    ((ExploratoryCreateAzure) exploratoryCreate)
-                            .withAzureClientId(settingsDAO.getAzureDataLakeClientId())
-                            .withAzureUserRefreshToken(userInfo.getKeys().get(AZURE_REFRESH_TOKEN_KEY));
-                }
-
-                ((ExploratoryCreateAzure) exploratoryCreate)
-                        .withAzureDataLakeEnabled(Boolean.toString(settingsDAO.isAzureDataLakeEnabled()));
-                break;
-            case GCP:
-                exploratoryCreate = (T) newResourceSysBaseDTO(userInfo, ExploratoryCreateGcp.class)
-                        .withNotebookInstanceType(exploratory.getShape());
-                break;
-
-            default:
-                throw new IllegalArgumentException(UNSUPPORTED_CLOUD_PROVIDER_MESSAGE + cloudProvider());
-        }
-
-        return exploratoryCreate.withExploratoryName(exploratory.getName())
-                .withNotebookImage(exploratory.getDockerImage())
-                .withApplicationName(getApplicationNameFromImage(exploratory.getDockerImage()))
-                .withGitCreds(exploratoryGitCredsDTO.getGitCreds())
-                .withImageName(exploratory.getImageName())
-                .withClusterConfig(exploratory.getClusterConfig());
-    }
-
-    @SuppressWarnings("unchecked")
-    public <T extends ExploratoryGitCredsUpdateDTO> T newExploratoryStart(UserInfo userInfo,
-                                                                          UserInstanceDTO userInstance,
-                                                                          ExploratoryGitCredsDTO
-                                                                                  exploratoryGitCredsDTO) {
-
-        switch (cloudProvider()) {
-            case AWS:
-            case GCP:
-                return (T) newResourceSysBaseDTO(userInfo, ExploratoryGitCredsUpdateDTO.class)
-                        .withNotebookInstanceName(userInstance.getExploratoryId())
-                        .withGitCreds(exploratoryGitCredsDTO.getGitCreds())
-                        .withNotebookImage(userInstance.getImageName())
-                        .withExploratoryName(userInstance.getExploratoryName())
-                        .withReuploadKeyRequired(userInstance.isReuploadKeyRequired());
-            case AZURE:
-                T exploratoryStart = (T) newResourceSysBaseDTO(userInfo, ExploratoryActionStartAzure.class)
-                        .withNotebookInstanceName(userInstance.getExploratoryId())
-                        .withGitCreds(exploratoryGitCredsDTO.getGitCreds())
-                        .withNotebookImage(userInstance.getImageName())
-                        .withExploratoryName(userInstance.getExploratoryName())
-                        .withReuploadKeyRequired(userInstance.isReuploadKeyRequired());
-
-                if (settingsDAO.isAzureDataLakeEnabled()) {
-                    ((ExploratoryActionStartAzure) exploratoryStart)
-                            .withAzureClientId(settingsDAO.getAzureDataLakeClientId())
-                            .withAzureUserRefreshToken(userInfo.getKeys().get(AZURE_REFRESH_TOKEN_KEY));
-                }
-
-                ((ExploratoryActionStartAzure) exploratoryStart)
-                        .withAzureDataLakeEnabled(Boolean.toString(settingsDAO.isAzureDataLakeEnabled()));
-
-                return exploratoryStart;
-            default:
-                throw new IllegalArgumentException(UNSUPPORTED_CLOUD_PROVIDER_MESSAGE + cloudProvider());
-        }
-    }
-
-    @SuppressWarnings("unchecked")
-    public <T extends ExploratoryActionDTO<T>> T newExploratoryStop(UserInfo userInfo, UserInstanceDTO userInstance) {
-
-        T exploratoryStop;
-
-        switch (cloudProvider()) {
-            case AWS:
-            case GCP:
-                exploratoryStop = (T) newResourceSysBaseDTO(userInfo, ExploratoryActionDTO.class);
-                break;
-            case AZURE:
-                exploratoryStop = (T) newResourceSysBaseDTO(userInfo, ExploratoryActionStopAzure.class);
-                break;
-            default:
-                throw new IllegalArgumentException(UNSUPPORTED_CLOUD_PROVIDER_MESSAGE + cloudProvider());
-        }
-
-        return exploratoryStop
-                .withNotebookInstanceName(userInstance.getExploratoryId())
-                .withNotebookImage(userInstance.getImageName())
-                .withExploratoryName(userInstance.getExploratoryName())
-                .withNotebookImage(userInstance.getImageName())
-                .withReuploadKeyRequired(userInstance.isReuploadKeyRequired());
-    }
-
-    public ExploratoryGitCredsUpdateDTO newGitCredentialsUpdate(UserInfo userInfo, UserInstanceDTO instanceDTO,
-                                                                ExploratoryGitCredsDTO exploratoryGitCredsDTO) {
-        checkInappropriateCloudProviderOrElseThrowException();
-        return newResourceSysBaseDTO(userInfo, ExploratoryGitCredsUpdateDTO.class)
-                .withNotebookImage(instanceDTO.getImageName())
-                .withApplicationName(getApplicationNameFromImage(instanceDTO.getImageName()))
-                .withNotebookInstanceName(instanceDTO.getExploratoryId())
-                .withExploratoryName(instanceDTO.getExploratoryName())
-                .withGitCreds(exploratoryGitCredsDTO.getGitCreds());
-    }
-
-    public LibraryInstallDTO newLibInstall(UserInfo userInfo, UserInstanceDTO userInstance,
-                                           List<LibInstallDTO> libs) {
-        checkInappropriateCloudProviderOrElseThrowException();
-        return newResourceSysBaseDTO(userInfo, LibraryInstallDTO.class)
-                .withNotebookImage(userInstance.getImageName())
-                .withApplicationName(getApplicationNameFromImage(userInstance.getImageName()))
-                .withNotebookInstanceName(userInstance.getExploratoryId())
-                .withExploratoryName(userInstance.getExploratoryName())
-                .withLibs(libs);
-    }
-
-    @SuppressWarnings("unchecked")
-    public <T extends ExploratoryActionDTO<T>> T newLibExploratoryList(UserInfo userInfo,
-                                                                       UserInstanceDTO userInstance) {
-        checkInappropriateCloudProviderOrElseThrowException();
-        return (T) newResourceSysBaseDTO(userInfo, ExploratoryActionDTO.class)
-                .withNotebookInstanceName(userInstance.getExploratoryId())
-                .withNotebookImage(userInstance.getImageName())
-                .withApplicationName(getApplicationNameFromImage(userInstance.getImageName()))
-                .withExploratoryName(userInstance.getExploratoryName());
-    }
-
-    @SuppressWarnings("unchecked")
-    public <T extends LibraryInstallDTO> T newLibInstall(UserInfo userInfo, UserInstanceDTO userInstance,
-                                                         UserComputationalResource computationalResource,
-                                                         List<LibInstallDTO> libs) {
-        checkInappropriateCloudProviderOrElseThrowException();
-        return (T) newResourceSysBaseDTO(userInfo, LibraryInstallDTO.class)
-                .withComputationalId(computationalResource.getComputationalId())
-                .withComputationalName(computationalResource.getComputationalName())
-                .withExploratoryName(userInstance.getExploratoryName())
-                .withComputationalImage(computationalResource.getImageName())
-                .withApplicationName(getApplicationNameFromImage(userInstance.getImageName()))
-                .withLibs(libs);
-    }
-
-    @SuppressWarnings("unchecked")
-    public <T extends LibListComputationalDTO> T newLibComputationalList(UserInfo userInfo,
-                                                                         UserInstanceDTO userInstance,
-                                                                         UserComputationalResource
-                                                                                 computationalResource) {
-
-        checkInappropriateCloudProviderOrElseThrowException();
-        return (T) newResourceSysBaseDTO(userInfo, LibListComputationalDTO.class)
-                .withComputationalId(computationalResource.getComputationalId())
-                .withComputationalImage(computationalResource.getImageName())
-                .withLibCacheKey(ExploratoryLibCache.libraryCacheKey(userInstance))
-                .withApplicationName(getApplicationNameFromImage(userInstance.getImageName()));
-    }
-
-    @SuppressWarnings("unchecked")
-    public <T extends ComputationalBase<T>> T newComputationalCreate(UserInfo userInfo,
-                                                                     UserInstanceDTO userInstance,
-                                                                     ComputationalCreateFormDTO form) {
-        T computationalCreate;
-
-        switch (cloudProvider()) {
-            case AZURE:
-                throw new UnsupportedOperationException("Creating dataengine service is not supported yet");
-            case AWS:
-                AwsComputationalCreateForm awsForm = (AwsComputationalCreateForm) form;
-                computationalCreate = (T) newResourceSysBaseDTO(userInfo, ComputationalCreateAws.class)
-                        .withInstanceCount(awsForm.getInstanceCount())
-                        .withMasterInstanceType(awsForm.getMasterInstanceType())
-                        .withSlaveInstanceType(awsForm.getSlaveInstanceType())
-                        .withSlaveInstanceSpot(awsForm.getSlaveInstanceSpot())
-                        .withSlaveInstanceSpotPctPrice(awsForm.getSlaveInstanceSpotPctPrice())
-                        .withVersion(awsForm.getVersion())
-                        .withConfig((awsForm.getConfig()));
-                break;
-            case GCP:
-                GcpComputationalCreateForm gcpForm = (GcpComputationalCreateForm) form;
-                computationalCreate = (T) newResourceSysBaseDTO(userInfo, ComputationalCreateGcp.class)
-                        .withMasterInstanceCount(gcpForm.getMasterInstanceCount())
-                        .withSlaveInstanceCount(gcpForm.getSlaveInstanceCount())
-                        .withPreemptibleCount(gcpForm.getPreemptibleCount())
-                        .withMasterInstanceType(gcpForm.getMasterInstanceType())
-                        .withSlaveInstanceType(gcpForm.getSlaveInstanceType())
-                        .withVersion(gcpForm.getVersion());
-                break;
-
-            default:
-                throw new IllegalArgumentException(UNSUPPORTED_CLOUD_PROVIDER_MESSAGE + cloudProvider());
-        }
-
-        return computationalCreate
-                .withExploratoryName(form.getNotebookName())
-                .withComputationalName(form.getName())
-                .withNotebookTemplateName(userInstance.getTemplateName())
-                .withApplicationName(getApplicationNameFromImage(userInstance.getImageName()))
-                .withNotebookInstanceName(userInstance.getExploratoryId());
-    }
-
-    @SuppressWarnings("unchecked")
-    public <T extends ComputationalBase<T>> T newComputationalCreate(UserInfo userInfo,
-                                                                     UserInstanceDTO userInstance,
-                                                                     SparkStandaloneClusterCreateForm form) {
-
-        T computationalCreate;
-
-        switch (cloudProvider()) {
-            case AWS:
-                computationalCreate = (T) newResourceSysBaseDTO(userInfo, SparkComputationalCreateAws.class)
-                        .withDataEngineInstanceCount(form.getDataEngineInstanceCount())
-                        .withDataEngineMasterShape(form.getDataEngineInstanceShape())
-                        .withDataEngineSlaveShape(form.getDataEngineInstanceShape())
-                        .withConfig(form.getConfig());
-                break;
-            case AZURE:
-                computationalCreate = (T) newResourceSysBaseDTO(userInfo, SparkComputationalCreateAzure.class)
-                        .withDataEngineInstanceCount(form.getDataEngineInstanceCount())
-                        .withDataEngineMasterSize(form.getDataEngineInstanceShape())
-                        .withDataEngineSlaveSize(form.getDataEngineInstanceShape())
-                        .withConfig(form.getConfig());
-                if (settingsDAO.isAzureDataLakeEnabled()) {
-                    ((SparkComputationalCreateAzure) computationalCreate)
-                            .withAzureClientId(settingsDAO.getAzureDataLakeClientId())
-                            .withAzureUserRefreshToken(userInfo.getKeys().get(AZURE_REFRESH_TOKEN_KEY));
-                }
-
-                ((SparkComputationalCreateAzure) computationalCreate)
-                        .withAzureDataLakeEnabled(Boolean.toString(settingsDAO.isAzureDataLakeEnabled()));
-
-                break;
-            case GCP:
-                computationalCreate = (T) newResourceSysBaseDTO(userInfo, SparkComputationalCreateGcp.class)
-                        .withDataEngineInstanceCount(form.getDataEngineInstanceCount())
-                        .withDataEngineMasterSize(form.getDataEngineInstanceShape())
-                        .withDataEngineSlaveSize(form.getDataEngineInstanceShape())
-                        .withConfig(form.getConfig());
-                break;
-            default:
-                throw new IllegalArgumentException(UNSUPPORTED_CLOUD_PROVIDER_MESSAGE + cloudProvider());
-        }
-
-        return computationalCreate
-                .withExploratoryName(form.getNotebookName())
-                .withComputationalName(form.getName())
-                .withNotebookTemplateName(userInstance.getTemplateName())
-                .withApplicationName(getApplicationNameFromImage(userInstance.getImageName()))
-                .withNotebookInstanceName(userInstance.getExploratoryId());
-    }
-
-    @SuppressWarnings("unchecked")
-    public <T extends ComputationalBase<T>> T newComputationalTerminate(UserInfo userInfo,
-                                                                        String exploratoryName,
-                                                                        String exploratoryId,
-                                                                        String computationalName,
-                                                                        String computationalId,
-                                                                        DataEngineType dataEngineType) {
-        T computationalTerminate;
-
-        switch (cloudProvider()) {
-            case AWS:
-                AwsComputationalTerminateDTO terminateDTO = newResourceSysBaseDTO(userInfo,
-                        AwsComputationalTerminateDTO.class);
-                if (dataEngineType == DataEngineType.CLOUD_SERVICE) {
-                    terminateDTO.setClusterName(computationalId);
-                }
-                computationalTerminate = (T) terminateDTO;
-                break;
-            case AZURE:
-                computationalTerminate = (T) newResourceSysBaseDTO(userInfo, ComputationalTerminateDTO.class);
-                break;
-            case GCP:
-                GcpComputationalTerminateDTO gcpTerminateDTO = newResourceSysBaseDTO(userInfo,
-                        GcpComputationalTerminateDTO.class);
-                if (dataEngineType == DataEngineType.CLOUD_SERVICE) {
-                    gcpTerminateDTO.setClusterName(computationalId);
-                }
-                computationalTerminate = (T) gcpTerminateDTO;
-                break;
-
-            default:
-                throw new IllegalArgumentException(UNSUPPORTED_CLOUD_PROVIDER_MESSAGE + cloudProvider());
-        }
-
-        return computationalTerminate
-                .withExploratoryName(exploratoryName)
-                .withComputationalName(computationalName)
-                .withNotebookInstanceName(exploratoryId);
-    }
-
-    @SuppressWarnings("unchecked")
-    public <T extends ComputationalBase<T>> T newComputationalStop(UserInfo userInfo,
-                                                                   UserInstanceDTO exploratory,
-                                                                   String computationalName) {
-        return (T) newResourceSysBaseDTO(userInfo, ComputationalStopDTO.class)
-                .withExploratoryName(exploratory.getExploratoryName())
-                .withComputationalName(computationalName)
-                .withNotebookInstanceName(exploratory.getExploratoryId())
-                .withApplicationName(getApplicationNameFromImage(exploratory.getImageName()));
-    }
-
-    @SuppressWarnings("unchecked")
-    public <T extends ComputationalBase<T>> T newComputationalStart(UserInfo userInfo, UserInstanceDTO exploratory,
-                                                                    String computationalName) {
-        return (T) newResourceSysBaseDTO(userInfo, ComputationalStartDTO.class)
-                .withExploratoryName(exploratory.getExploratoryName())
-                .withComputationalName(computationalName)
-                .withNotebookInstanceName(exploratory.getExploratoryId())
-                .withApplicationName(getApplicationNameFromImage(exploratory.getImageName()));
-    }
-
-    @SuppressWarnings("unchecked")
-    public <T extends ExploratoryImageDTO> T newExploratoryImageCreate(UserInfo userInfo, UserInstanceDTO userInstance,
-                                                                       String imageName) {
-        checkInappropriateCloudProviderOrElseThrowException();
-        return (T) newResourceSysBaseDTO(userInfo, ExploratoryImageDTO.class)
-                .withNotebookInstanceName(userInstance.getExploratoryId())
-                .withExploratoryName(userInstance.getExploratoryName())
-                .withApplicationName(getApplicationNameFromImage(userInstance.getImageName()))
-                .withNotebookImage(userInstance.getImageName())
-                .withImageName(imageName);
-    }
-
-
-    @SuppressWarnings("unchecked")
-    public <T extends EnvBackupDTO> T newBackupCreate(BackupFormDTO backupFormDTO, String id) {
-
-        return (T) EnvBackupDTO.builder()
-                .configFiles(backupFormDTO.getConfigFiles())
-                .certificates(backupFormDTO.getCertificates())
-                .keys(backupFormDTO.getKeys())
-                .jars(backupFormDTO.getJars())
-                .databaseBackup(backupFormDTO.isDatabaseBackup())
-                .logsBackup(backupFormDTO.isLogsBackup())
-                .id(id)
-                .build();
-    }
-
-    public ComputationalClusterConfigDTO newClusterConfigUpdate(UserInfo userInfo, UserInstanceDTO userInstanceDTO,
-                                                                UserComputationalResource compRes,
-                                                                List<ClusterConfig> config) {
-        final ComputationalClusterConfigDTO clusterConfigDTO = newResourceSysBaseDTO(userInfo,
-                ComputationalClusterConfigDTO.class)
-                .withExploratoryName(userInstanceDTO.getExploratoryName())
-                .withNotebookInstanceName(userInstanceDTO.getExploratoryId())
-                .withComputationalName(compRes.getComputationalName())
-                .withApplicationName(compRes.getImageName());
-        clusterConfigDTO.setCopmutationalId(compRes.getComputationalId());
-        clusterConfigDTO.setConfig(config);
-        if (cloudProvider() == AZURE && settingsDAO.isAzureDataLakeEnabled()) {
-            clusterConfigDTO.setAzureUserRefreshToken(userInfo.getKeys().get(AZURE_REFRESH_TOKEN_KEY));
-        }
-
-        return clusterConfigDTO;
-    }
-
-    public ExploratoryReconfigureSparkClusterActionDTO newClusterConfigUpdate(UserInfo userInfo,
-                                                                              UserInstanceDTO userInstance,
-                                                                              List<ClusterConfig> config) {
-
-        final ExploratoryReconfigureSparkClusterActionDTO dto =
-                newResourceSysBaseDTO(userInfo, ExploratoryReconfigureSparkClusterActionDTO.class)
-                        .withNotebookInstanceName(userInstance.getExploratoryId())
-                        .withExploratoryName(userInstance.getExploratoryName())
-                        .withApplicationName(getApplicationNameFromImage(userInstance.getImageName()))
-                        .withNotebookImage(userInstance.getImageName())
-                        .withConfig(config);
-        if (cloudProvider() == AZURE && settingsDAO.isAzureDataLakeEnabled()) {
-            dto.withAzureUserRefreshToken(userInfo.getKeys().get(AZURE_REFRESH_TOKEN_KEY));
-        }
-
-        return dto;
-
-
-    }
-
-    private CloudProvider cloudProvider() {
-        return configuration.getCloudProvider();
-    }
-
-    /**
-     * Returns application name basing on docker image
-     *
-     * @param imageName docker image name
-     * @return application name
-     */
-    private String getApplicationNameFromImage(String imageName) {
-        if (imageName != null) {
-            int pos = imageName.indexOf('-');
-            if (pos > 0) {
-                return imageName.substring(pos + 1);
-            }
-        }
-        return "";
-    }
-
-    private void checkInappropriateCloudProviderOrElseThrowException() {
-        CloudProvider provider = cloudProvider();
-        if (provider != AWS && provider != AZURE && provider != GCP) {
-            throw new IllegalArgumentException(UNSUPPORTED_CLOUD_PROVIDER_MESSAGE + provider);
-        }
-    }
+	private static final String UNSUPPORTED_CLOUD_PROVIDER_MESSAGE = "Unsupported cloud provider ";
+	private static final String AZURE_REFRESH_TOKEN_KEY = "refresh_token";
+
+	@Inject
+	private SelfServiceApplicationConfiguration configuration;
+	@Inject
+	private SettingsDAO settingsDAO;
+
+	private CloudSettings cloudSettings(UserInfo userInfo) {
+		switch (cloudProvider()) {
+			case AWS:
+				return AwsCloudSettings.builder()
+						.awsRegion(settingsDAO.getAwsRegion())
+						.awsSecurityGroupIds(settingsDAO.getAwsSecurityGroups())
+						.awsSubnetId(settingsDAO.getAwsSubnetId())
+						.awsVpcId(settingsDAO.getAwsVpcId())
+						.confTagResourceId(settingsDAO.getConfTagResourceId())
+						.awsNotebookSubnetId(settingsDAO.getAwsNotebookSubnetId())
+						.awsNotebookVpcId(settingsDAO.getAwsNotebookVpcId())
+						.awsIamUser(userInfo.getName()).build();
+			case AZURE:
+				return AzureCloudSettings.builder()
+						.azureRegion(settingsDAO.getAzureRegion())
+						.azureResourceGroupName(settingsDAO.getAzureResourceGroupName())
+						.azureSecurityGroupName(settingsDAO.getAzureSecurityGroupName())
+						.azureSubnetName(settingsDAO.getAzureSubnetName())
+						.azureVpcName(settingsDAO.getAzureVpcName())
+						.azureIamUser(userInfo.getName()).build();
+			case GCP:
+				return GcpCloudSettings.builder().gcpIamUser(userInfo.getName()).build();
+			default:
+				throw new IllegalArgumentException(UNSUPPORTED_CLOUD_PROVIDER_MESSAGE + cloudProvider());
+		}
+	}
+
+	@SuppressWarnings("unchecked")
+	private <T extends ResourceBaseDTO<?>> T newResourceBaseDTO(UserInfo userInfo, Class<T> resourceClass) {
+		try {
+			return (T) resourceClass.newInstance()
+					.withEdgeUserName(getEdgeUserName(userInfo))
+					.withCloudSettings(cloudSettings(userInfo));
+		} catch (Exception e) {
+			throw new DlabException("Cannot create instance of resource class " + resourceClass.getName() + ". " +
+					e.getLocalizedMessage(), e);
+		}
+	}
+
+	private String getEdgeUserName(UserInfo userInfo) {
+		String edgeUser = UsernameUtils.replaceWhitespaces(userInfo.getSimpleName());
+		switch (cloudProvider()) {
+			case GCP:
+				return adjustUserName(configuration.getMaxUserNameLength(), edgeUser);
+			case AWS:
+			case AZURE:
+				return edgeUser;
+			default:
+				throw new DlabException(UNSUPPORTED_CLOUD_PROVIDER_MESSAGE + cloudProvider());
+		}
+	}
+
+	private String adjustUserName(int maxLength, String userName) {
+		return userName.length() > maxLength ?
+				UUID.nameUUIDFromBytes(userName.getBytes()).toString().substring(0, maxLength) : userName;
+	}
+
+	@SuppressWarnings("unchecked")
+	private <T extends ResourceSysBaseDTO<?>> T newResourceSysBaseDTO(UserInfo userInfo, Class<T> resourceClass) {
+		T resource = newResourceBaseDTO(userInfo, resourceClass);
+		return (T) resource
+				.withServiceBaseName(settingsDAO.getServiceBaseName())
+				.withConfOsFamily(settingsDAO.getConfOsFamily());
+	}
+
+	@SuppressWarnings("unchecked")
+	public UploadFile newEdgeKeyUpload(UserInfo userInfo, String content) {
+
+		switch (cloudProvider()) {
+			case AWS:
+				EdgeCreateAws edgeCreateAws = newResourceSysBaseDTO(userInfo, EdgeCreateAws.class);
+				UploadFileAws uploadFileAws = new UploadFileAws();
+				uploadFileAws.setEdge(edgeCreateAws);
+				uploadFileAws.setContent(content);
+
+				return uploadFileAws;
+
+			case AZURE:
+				EdgeCreateAzure edgeCreateAzure = newResourceSysBaseDTO(userInfo, EdgeCreateAzure.class)
+						.withAzureDataLakeEnable(Boolean.toString(settingsDAO.isAzureDataLakeEnabled()));
+
+				UploadFileAzure uploadFileAzure = new UploadFileAzure();
+				uploadFileAzure.setEdge(edgeCreateAzure);
+				uploadFileAzure.setContent(content);
+
+				return uploadFileAzure;
+
+			case GCP:
+				return new UploadFileGcp(newResourceSysBaseDTO(userInfo, EdgeCreateGcp.class), content);
+			default:
+				throw new IllegalArgumentException(UNSUPPORTED_CLOUD_PROVIDER_MESSAGE + cloudProvider());
+		}
+	}
+
+	public ReuploadKeyDTO newKeyReupload(UserInfo userInfo, String id, String content, List<ResourceData> resources) {
+		return newResourceSysBaseDTO(userInfo, ReuploadKeyDTO.class)
+				.withId(id)
+				.withContent(content)
+				.withResources(resources);
+	}
+
+	@SuppressWarnings("unchecked")
+	public <T extends ResourceSysBaseDTO<?>> T newEdgeAction(UserInfo userInfo) {
+		checkInappropriateCloudProviderOrElseThrowException();
+		return (T) newResourceSysBaseDTO(userInfo, ResourceSysBaseDTO.class);
+	}
+
+	public UserEnvironmentResources newUserEnvironmentStatus(UserInfo userInfo) {
+		checkInappropriateCloudProviderOrElseThrowException();
+		return newResourceSysBaseDTO(userInfo, UserEnvironmentResources.class);
+	}
+
+	@SuppressWarnings("unchecked")
+	public <T extends ExploratoryCreateDTO<T>> T newExploratoryCreate(Exploratory exploratory, UserInfo userInfo,
+																	  ExploratoryGitCredsDTO exploratoryGitCredsDTO) {
+
+		T exploratoryCreate;
+
+		switch (cloudProvider()) {
+			case AWS:
+				exploratoryCreate = (T) newResourceSysBaseDTO(userInfo, ExploratoryCreateAws.class)
+						.withNotebookInstanceType(exploratory.getShape());
+				break;
+			case AZURE:
+				exploratoryCreate = (T) newResourceSysBaseDTO(userInfo, ExploratoryCreateAzure.class)
+						.withNotebookInstanceSize(exploratory.getShape());
+				if (settingsDAO.isAzureDataLakeEnabled()) {
+					((ExploratoryCreateAzure) exploratoryCreate)
+							.withAzureUserRefreshToken(userInfo.getKeys().get(AZURE_REFRESH_TOKEN_KEY));
+				}
+
+				((ExploratoryCreateAzure) exploratoryCreate)
+						.withAzureDataLakeEnabled(Boolean.toString(settingsDAO.isAzureDataLakeEnabled()));
+				break;
+			case GCP:
+				exploratoryCreate = (T) newResourceSysBaseDTO(userInfo, ExploratoryCreateGcp.class)
+						.withNotebookInstanceType(exploratory.getShape());
+				break;
+
+			default:
+				throw new IllegalArgumentException(UNSUPPORTED_CLOUD_PROVIDER_MESSAGE + cloudProvider());
+		}
+
+		return exploratoryCreate.withExploratoryName(exploratory.getName())
+				.withNotebookImage(exploratory.getDockerImage())
+				.withApplicationName(getApplicationNameFromImage(exploratory.getDockerImage()))
+				.withGitCreds(exploratoryGitCredsDTO.getGitCreds())
+				.withImageName(exploratory.getImageName())
+				.withClusterConfig(exploratory.getClusterConfig());
+	}
+
+	@SuppressWarnings("unchecked")
+	public <T extends ExploratoryGitCredsUpdateDTO> T newExploratoryStart(UserInfo userInfo,
+																		  UserInstanceDTO userInstance,
+																		  ExploratoryGitCredsDTO
+																				  exploratoryGitCredsDTO) {
+
+		switch (cloudProvider()) {
+			case AWS:
+			case GCP:
+				return (T) newResourceSysBaseDTO(userInfo, ExploratoryGitCredsUpdateDTO.class)
+						.withNotebookInstanceName(userInstance.getExploratoryId())
+						.withGitCreds(exploratoryGitCredsDTO.getGitCreds())
+						.withNotebookImage(userInstance.getImageName())
+						.withExploratoryName(userInstance.getExploratoryName())
+						.withReuploadKeyRequired(userInstance.isReuploadKeyRequired());
+			case AZURE:
+				T exploratoryStart = (T) newResourceSysBaseDTO(userInfo, ExploratoryActionStartAzure.class)
+						.withNotebookInstanceName(userInstance.getExploratoryId())
+						.withGitCreds(exploratoryGitCredsDTO.getGitCreds())
+						.withNotebookImage(userInstance.getImageName())
+						.withExploratoryName(userInstance.getExploratoryName())
+						.withReuploadKeyRequired(userInstance.isReuploadKeyRequired());
+
+				if (settingsDAO.isAzureDataLakeEnabled()) {
+					((ExploratoryActionStartAzure) exploratoryStart)
+							.withAzureUserRefreshToken(userInfo.getKeys().get(AZURE_REFRESH_TOKEN_KEY));
+				}
+
+				((ExploratoryActionStartAzure) exploratoryStart)
+						.withAzureDataLakeEnabled(Boolean.toString(settingsDAO.isAzureDataLakeEnabled()));
+
+				return exploratoryStart;
+			default:
+				throw new IllegalArgumentException(UNSUPPORTED_CLOUD_PROVIDER_MESSAGE + cloudProvider());
+		}
+	}
+
+	@SuppressWarnings("unchecked")
+	public <T extends ExploratoryActionDTO<T>> T newExploratoryStop(UserInfo userInfo, UserInstanceDTO userInstance) {
+
+		T exploratoryStop;
+
+		switch (cloudProvider()) {
+			case AWS:
+			case GCP:
+				exploratoryStop = (T) newResourceSysBaseDTO(userInfo, ExploratoryActionDTO.class);
+				break;
+			case AZURE:
+				exploratoryStop = (T) newResourceSysBaseDTO(userInfo, ExploratoryActionStopAzure.class);
+				break;
+			default:
+				throw new IllegalArgumentException(UNSUPPORTED_CLOUD_PROVIDER_MESSAGE + cloudProvider());
+		}
+
+		return exploratoryStop
+				.withNotebookInstanceName(userInstance.getExploratoryId())
+				.withNotebookImage(userInstance.getImageName())
+				.withExploratoryName(userInstance.getExploratoryName())
+				.withNotebookImage(userInstance.getImageName())
+				.withReuploadKeyRequired(userInstance.isReuploadKeyRequired());
+	}
+
+	public ExploratoryGitCredsUpdateDTO newGitCredentialsUpdate(UserInfo userInfo, UserInstanceDTO instanceDTO,
+																ExploratoryGitCredsDTO exploratoryGitCredsDTO) {
+		checkInappropriateCloudProviderOrElseThrowException();
+		return newResourceSysBaseDTO(userInfo, ExploratoryGitCredsUpdateDTO.class)
+				.withNotebookImage(instanceDTO.getImageName())
+				.withApplicationName(getApplicationNameFromImage(instanceDTO.getImageName()))
+				.withNotebookInstanceName(instanceDTO.getExploratoryId())
+				.withExploratoryName(instanceDTO.getExploratoryName())
+				.withGitCreds(exploratoryGitCredsDTO.getGitCreds());
+	}
+
+	public LibraryInstallDTO newLibInstall(UserInfo userInfo, UserInstanceDTO userInstance,
+										   List<LibInstallDTO> libs) {
+		checkInappropriateCloudProviderOrElseThrowException();
+		return newResourceSysBaseDTO(userInfo, LibraryInstallDTO.class)
+				.withNotebookImage(userInstance.getImageName())
+				.withApplicationName(getApplicationNameFromImage(userInstance.getImageName()))
+				.withNotebookInstanceName(userInstance.getExploratoryId())
+				.withExploratoryName(userInstance.getExploratoryName())
+				.withLibs(libs);
+	}
+
+	@SuppressWarnings("unchecked")
+	public <T extends ExploratoryActionDTO<T>> T newLibExploratoryList(UserInfo userInfo,
+																	   UserInstanceDTO userInstance) {
+		checkInappropriateCloudProviderOrElseThrowException();
+		return (T) newResourceSysBaseDTO(userInfo, ExploratoryActionDTO.class)
+				.withNotebookInstanceName(userInstance.getExploratoryId())
+				.withNotebookImage(userInstance.getImageName())
+				.withApplicationName(getApplicationNameFromImage(userInstance.getImageName()))
+				.withExploratoryName(userInstance.getExploratoryName());
+	}
+
+	@SuppressWarnings("unchecked")
+	public <T extends LibraryInstallDTO> T newLibInstall(UserInfo userInfo, UserInstanceDTO userInstance,
+														 UserComputationalResource computationalResource,
+														 List<LibInstallDTO> libs) {
+		checkInappropriateCloudProviderOrElseThrowException();
+		return (T) newResourceSysBaseDTO(userInfo, LibraryInstallDTO.class)
+				.withComputationalId(computationalResource.getComputationalId())
+				.withComputationalName(computationalResource.getComputationalName())
+				.withExploratoryName(userInstance.getExploratoryName())
+				.withComputationalImage(computationalResource.getImageName())
+				.withApplicationName(getApplicationNameFromImage(userInstance.getImageName()))
+				.withLibs(libs);
+	}
+
+	@SuppressWarnings("unchecked")
+	public <T extends LibListComputationalDTO> T newLibComputationalList(UserInfo userInfo,
+																		 UserInstanceDTO userInstance,
+																		 UserComputationalResource
+																				 computationalResource) {
+
+		checkInappropriateCloudProviderOrElseThrowException();
+		return (T) newResourceSysBaseDTO(userInfo, LibListComputationalDTO.class)
+				.withComputationalId(computationalResource.getComputationalId())
+				.withComputationalImage(computationalResource.getImageName())
+				.withLibCacheKey(ExploratoryLibCache.libraryCacheKey(userInstance))
+				.withApplicationName(getApplicationNameFromImage(userInstance.getImageName()));
+	}
+
+	@SuppressWarnings("unchecked")
+	public <T extends ComputationalBase<T>> T newComputationalCreate(UserInfo userInfo,
+																	 UserInstanceDTO userInstance,
+																	 ComputationalCreateFormDTO form) {
+		T computationalCreate;
+
+		switch (cloudProvider()) {
+			case AZURE:
+				throw new UnsupportedOperationException("Creating dataengine service is not supported yet");
+			case AWS:
+				AwsComputationalCreateForm awsForm = (AwsComputationalCreateForm) form;
+				computationalCreate = (T) newResourceSysBaseDTO(userInfo, ComputationalCreateAws.class)
+						.withInstanceCount(awsForm.getInstanceCount())
+						.withMasterInstanceType(awsForm.getMasterInstanceType())
+						.withSlaveInstanceType(awsForm.getSlaveInstanceType())
+						.withSlaveInstanceSpot(awsForm.getSlaveInstanceSpot())
+						.withSlaveInstanceSpotPctPrice(awsForm.getSlaveInstanceSpotPctPrice())
+						.withVersion(awsForm.getVersion())
+						.withConfig((awsForm.getConfig()));
+				break;
+			case GCP:
+				GcpComputationalCreateForm gcpForm = (GcpComputationalCreateForm) form;
+				computationalCreate = (T) newResourceSysBaseDTO(userInfo, ComputationalCreateGcp.class)
+						.withMasterInstanceCount(gcpForm.getMasterInstanceCount())
+						.withSlaveInstanceCount(gcpForm.getSlaveInstanceCount())
+						.withPreemptibleCount(gcpForm.getPreemptibleCount())
+						.withMasterInstanceType(gcpForm.getMasterInstanceType())
+						.withSlaveInstanceType(gcpForm.getSlaveInstanceType())
+						.withVersion(gcpForm.getVersion());
+				break;
+
+			default:
+				throw new IllegalArgumentException(UNSUPPORTED_CLOUD_PROVIDER_MESSAGE + cloudProvider());
+		}
+
+		return computationalCreate
+				.withExploratoryName(form.getNotebookName())
+				.withComputationalName(form.getName())
+				.withNotebookTemplateName(userInstance.getTemplateName())
+				.withApplicationName(getApplicationNameFromImage(userInstance.getImageName()))
+				.withNotebookInstanceName(userInstance.getExploratoryId());
+	}
+
+	@SuppressWarnings("unchecked")
+	public <T extends ComputationalBase<T>> T newComputationalCreate(UserInfo userInfo,
+																	 UserInstanceDTO userInstance,
+																	 SparkStandaloneClusterCreateForm form) {
+
+		T computationalCreate;
+
+		switch (cloudProvider()) {
+			case AWS:
+				computationalCreate = (T) newResourceSysBaseDTO(userInfo, SparkComputationalCreateAws.class)
+						.withDataEngineInstanceCount(form.getDataEngineInstanceCount())
+						.withDataEngineMasterShape(form.getDataEngineInstanceShape())
+						.withDataEngineSlaveShape(form.getDataEngineInstanceShape())
+						.withConfig(form.getConfig());
+				break;
+			case AZURE:
+				computationalCreate = (T) newResourceSysBaseDTO(userInfo, SparkComputationalCreateAzure.class)
+						.withDataEngineInstanceCount(form.getDataEngineInstanceCount())
+						.withDataEngineMasterSize(form.getDataEngineInstanceShape())
+						.withDataEngineSlaveSize(form.getDataEngineInstanceShape())
+						.withConfig(form.getConfig());
+				if (settingsDAO.isAzureDataLakeEnabled()) {
+					((SparkComputationalCreateAzure) computationalCreate)
+							.withAzureUserRefreshToken(userInfo.getKeys().get(AZURE_REFRESH_TOKEN_KEY));
+				}
+
+				((SparkComputationalCreateAzure) computationalCreate)
+						.withAzureDataLakeEnabled(Boolean.toString(settingsDAO.isAzureDataLakeEnabled()));
+
+				break;
+			case GCP:
+				computationalCreate = (T) newResourceSysBaseDTO(userInfo, SparkComputationalCreateGcp.class)
+						.withDataEngineInstanceCount(form.getDataEngineInstanceCount())
+						.withDataEngineMasterSize(form.getDataEngineInstanceShape())
+						.withDataEngineSlaveSize(form.getDataEngineInstanceShape())
+						.withConfig(form.getConfig());
+				break;
+			default:
+				throw new IllegalArgumentException(UNSUPPORTED_CLOUD_PROVIDER_MESSAGE + cloudProvider());
+		}
+
+		return computationalCreate
+				.withExploratoryName(form.getNotebookName())
+				.withComputationalName(form.getName())
+				.withNotebookTemplateName(userInstance.getTemplateName())
+				.withApplicationName(getApplicationNameFromImage(userInstance.getImageName()))
+				.withNotebookInstanceName(userInstance.getExploratoryId());
+	}
+
+	@SuppressWarnings("unchecked")
+	public <T extends ComputationalBase<T>> T newComputationalTerminate(UserInfo userInfo,
+																		String exploratoryName,
+																		String exploratoryId,
+																		String computationalName,
+																		String computationalId,
+																		DataEngineType dataEngineType) {
+		T computationalTerminate;
+
+		switch (cloudProvider()) {
+			case AWS:
+				AwsComputationalTerminateDTO terminateDTO = newResourceSysBaseDTO(userInfo,
+						AwsComputationalTerminateDTO.class);
+				if (dataEngineType == DataEngineType.CLOUD_SERVICE) {
+					terminateDTO.setClusterName(computationalId);
+				}
+				computationalTerminate = (T) terminateDTO;
+				break;
+			case AZURE:
+				computationalTerminate = (T) newResourceSysBaseDTO(userInfo, ComputationalTerminateDTO.class);
+				break;
+			case GCP:
+				GcpComputationalTerminateDTO gcpTerminateDTO = newResourceSysBaseDTO(userInfo,
+						GcpComputationalTerminateDTO.class);
+				if (dataEngineType == DataEngineType.CLOUD_SERVICE) {
+					gcpTerminateDTO.setClusterName(computationalId);
+				}
+				computationalTerminate = (T) gcpTerminateDTO;
+				break;
+
+			default:
+				throw new IllegalArgumentException(UNSUPPORTED_CLOUD_PROVIDER_MESSAGE + cloudProvider());
+		}
+
+		return computationalTerminate
+				.withExploratoryName(exploratoryName)
+				.withComputationalName(computationalName)
+				.withNotebookInstanceName(exploratoryId);
+	}
+
+	@SuppressWarnings("unchecked")
+	public <T extends ComputationalBase<T>> T newComputationalStop(UserInfo userInfo,
+																   UserInstanceDTO exploratory,
+																   String computationalName) {
+		return (T) newResourceSysBaseDTO(userInfo, ComputationalStopDTO.class)
+				.withExploratoryName(exploratory.getExploratoryName())
+				.withComputationalName(computationalName)
+				.withNotebookInstanceName(exploratory.getExploratoryId())
+				.withApplicationName(getApplicationNameFromImage(exploratory.getImageName()));
+	}
+
+	@SuppressWarnings("unchecked")
+	public <T extends ComputationalBase<T>> T newComputationalStart(UserInfo userInfo, UserInstanceDTO exploratory,
+																	String computationalName) {
+		return (T) newResourceSysBaseDTO(userInfo, ComputationalStartDTO.class)
+				.withExploratoryName(exploratory.getExploratoryName())
+				.withComputationalName(computationalName)
+				.withNotebookInstanceName(exploratory.getExploratoryId())
+				.withApplicationName(getApplicationNameFromImage(exploratory.getImageName()));
+	}
+
+	@SuppressWarnings("unchecked")
+	public <T extends ExploratoryImageDTO> T newExploratoryImageCreate(UserInfo userInfo, UserInstanceDTO userInstance,
+																	   String imageName) {
+		checkInappropriateCloudProviderOrElseThrowException();
+		return (T) newResourceSysBaseDTO(userInfo, ExploratoryImageDTO.class)
+				.withNotebookInstanceName(userInstance.getExploratoryId())
+				.withExploratoryName(userInstance.getExploratoryName())
+				.withApplicationName(getApplicationNameFromImage(userInstance.getImageName()))
+				.withNotebookImage(userInstance.getImageName())
+				.withImageName(imageName);
+	}
+
+
+	@SuppressWarnings("unchecked")
+	public <T extends EnvBackupDTO> T newBackupCreate(BackupFormDTO backupFormDTO, String id) {
+
+		return (T) EnvBackupDTO.builder()
+				.configFiles(backupFormDTO.getConfigFiles())
+				.certificates(backupFormDTO.getCertificates())
+				.keys(backupFormDTO.getKeys())
+				.jars(backupFormDTO.getJars())
+				.databaseBackup(backupFormDTO.isDatabaseBackup())
+				.logsBackup(backupFormDTO.isLogsBackup())
+				.id(id)
+				.build();
+	}
+
+	public ComputationalClusterConfigDTO newClusterConfigUpdate(UserInfo userInfo, UserInstanceDTO userInstanceDTO,
+																UserComputationalResource compRes,
+																List<ClusterConfig> config) {
+		final ComputationalClusterConfigDTO clusterConfigDTO = newResourceSysBaseDTO(userInfo,
+				ComputationalClusterConfigDTO.class)
+				.withExploratoryName(userInstanceDTO.getExploratoryName())
+				.withNotebookInstanceName(userInstanceDTO.getExploratoryId())
+				.withComputationalName(compRes.getComputationalName())
+				.withApplicationName(compRes.getImageName());
+		clusterConfigDTO.setCopmutationalId(compRes.getComputationalId());
+		clusterConfigDTO.setConfig(config);
+		if (cloudProvider() == AZURE && settingsDAO.isAzureDataLakeEnabled()) {
+			clusterConfigDTO.setAzureUserRefreshToken(userInfo.getKeys().get(AZURE_REFRESH_TOKEN_KEY));
+		}
+
+		return clusterConfigDTO;
+	}
+
+	public ExploratoryReconfigureSparkClusterActionDTO newClusterConfigUpdate(UserInfo userInfo,
+																			  UserInstanceDTO userInstance,
+																			  List<ClusterConfig> config) {
+
+		final ExploratoryReconfigureSparkClusterActionDTO dto =
+				newResourceSysBaseDTO(userInfo, ExploratoryReconfigureSparkClusterActionDTO.class)
+						.withNotebookInstanceName(userInstance.getExploratoryId())
+						.withExploratoryName(userInstance.getExploratoryName())
+						.withApplicationName(getApplicationNameFromImage(userInstance.getImageName()))
+						.withNotebookImage(userInstance.getImageName())
+						.withConfig(config);
+		if (cloudProvider() == AZURE && settingsDAO.isAzureDataLakeEnabled()) {
+			dto.withAzureUserRefreshToken(userInfo.getKeys().get(AZURE_REFRESH_TOKEN_KEY));
+		}
+
+		return dto;
+
+
+	}
+
+	private CloudProvider cloudProvider() {
+		return configuration.getCloudProvider();
+	}
+
+	/**
+	 * Returns application name basing on docker image
+	 *
+	 * @param imageName docker image name
+	 * @return application name
+	 */
+	private String getApplicationNameFromImage(String imageName) {
+		if (imageName != null) {
+			int pos = imageName.indexOf('-');
+			if (pos > 0) {
+				return imageName.substring(pos + 1);
+			}
+		}
+		return "";
+	}
+
+	private void checkInappropriateCloudProviderOrElseThrowException() {
+		CloudProvider provider = cloudProvider();
+		if (provider != AWS && provider != AZURE && provider != GCP) {
+			throw new IllegalArgumentException(UNSUPPORTED_CLOUD_PROVIDER_MESSAGE + provider);
+		}
+	}
 }
 
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@dlab.apache.org
For additional commands, e-mail: commits-help@dlab.apache.org