Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (C) 2013-2015 Dell, 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 org.dasein.cloud.azure.platform;
 
 
 import java.net.*;

Created by Vlad_Munthiu on 11/19/2014.
 
     private Azure provider;
 
     private final String RESOURCE_SERVERS = "https://management.core.windows.net/%s/services/sqlservers/servers?contentview=generic";
     private final String RESOURCE_SERVERS_NONGEN = "https://management.core.windows.net/%s/services/sqlservers/servers";
     private final String RESOURCE_SERVER = "https://management.core.windows.net/%s/services/sqlservers/servers/%s";
     private final String RESOURCE_DATABASES = "https://management.core.windows.net/%s/services/sqlservers/servers/%s/databases";
     private final String RESOURCE_DATABASE = "https://management.core.windows.net/%s/services/sqlservers/servers/%s/databases/%s";
     private final String RESOURCE_LIST_DATABASES = "https://management.core.windows.net/%s/services/sqlservers/servers/%s/databases?contentview=generic";
     private final String RESOURCE_SUBSCRIPTION_META = "https://management.core.windows.net/%s/services/sqlservers/subscriptioninfo";
     private final String RESOURCE_LIST_RECOVERABLE_DATABASES = "https://management.core.windows.net/%s/services/sqlservers/servers/%s/recoverabledatabases?contentview=generic";
     private final String RESOURCE_RESTORE_DATABASE_OPERATIONS = "https://management.core.windows.net/%s/services/sqlservers/servers/%s/restoredatabaseoperations";
     private final String RESOURCE_SERVER_FIREWALL = "https://management.core.windows.net/%s/services/sqlservers/servers/%s/firewallrules";
     private final String RESOURCE_FIREWALL_RULE = "https://management.core.windows.net/%s/services/sqlservers/servers/%s/firewallrules/%s";
 
     public AzureSQLDatabaseSupportRequests(Azure provider){
         this. = provider;
     }
 
     public RequestBuilder createServer(ServerModel serverToCreate){
         RequestBuilder requestBuilder = RequestBuilder.post();
         addAzureCommonHeaders(requestBuilder);
         requestBuilder.setUri(String.format(this..getContext().getAccountNumber()));
         requestBuilder.setEntity(new DaseinObjectToXmlEntity<ServerModel>(serverToCreate));
         return requestBuilder;
     }
 
     public RequestBuilder listServers(){
         RequestBuilder requestBuilder = RequestBuilder.get();
         addAzureCommonHeaders(requestBuilder);
         requestBuilder.setUri(String.format(this..getContext().getAccountNumber()));
         return requestBuilder;
     }
 
     public RequestBuilder listServersNonGen(){
         RequestBuilder requestBuilder = RequestBuilder.get();
         addAzureCommonHeaders(requestBuilder);
         requestBuilder.setUri(String.format(this..getContext().getAccountNumber()));
         return requestBuilder;
     }
 
     public RequestBuilder deleteServer(String serverName){
         RequestBuilder requestBuilder = RequestBuilder.delete();
         addAzureCommonHeaders(requestBuilder);
         requestBuilder.setUri(String.format(this..getContext().getAccountNumber(), serverName));
         return requestBuilder;
     }
 
     public RequestBuilder createDatabase(String serverNameDatabaseServiceResourceModel dbToCreate){
         RequestBuilder requestBuilder = RequestBuilder.post();
         addAzureCommonHeaders(requestBuilder);
         requestBuilder.setUri(String.format(this..getContext().getAccountNumber(), serverName));
         requestBuilder.setEntity(new DaseinObjectToXmlEntity<DatabaseServiceResourceModel>(dbToCreate));
         return requestBuilder;
     }
 
     public RequestBuilder createDatabaseFromBackup(String serverNameCreateDatabaseRestoreModel createDatabaseRestoreModel){
         RequestBuilder requestBuilder = RequestBuilder.post();
         addAzureCommonHeaders(requestBuilder);
         requestBuilder.setUri(String.format(this..getContext().getAccountNumber(), serverName));
         requestBuilder.setEntity(new DaseinObjectToXmlEntity<CreateDatabaseRestoreModel>(createDatabaseRestoreModel));
         return requestBuilder;
     }
 
     public RequestBuilder listDatabases(String serverName){
        RequestBuilder requestBuilder = RequestBuilder.get();
        addAzureCommonHeaders(requestBuilder);
        requestBuilder.setUri(String.format(this..getContext().getAccountNumber(), serverName));
        return requestBuilder;
    }
    public RequestBuilder deleteDatabase(String serverNameString databaseNamethrows InternalException {
        RequestBuilder requestBuilder = RequestBuilder.delete();
        addAzureCommonHeaders(requestBuilder);
        requestBuilder.setUri(getEncodedUri(String.format(this..getContext().getAccountNumber(), serverNamedatabaseName)));
        return requestBuilder;
    }
        RequestBuilder requestBuilder = RequestBuilder.get();
        addAzureCommonHeaders(requestBuilder);
        requestBuilder.setUri(String.format(this..getContext().getAccountNumber()));
        return requestBuilder;
    }
    public RequestBuilder getDatabase(String serverNameString databaseNamethrows InternalException {
        RequestBuilder requestBuilder = RequestBuilder.get();
        addAzureCommonHeaders(requestBuilder);
        requestBuilder.setUri(getEncodedUri(String.format(this..getContext().getAccountNumber(), serverNamedatabaseName)));
        return requestBuilder;
    }
    public RequestBuilder getRecoverableDatabases(String serverName){
        RequestBuilder requestBuilder = RequestBuilder.get();
        addAzureCommonHeaders(requestBuilder);
        requestBuilder.setUri(String.format(this..getContext().getAccountNumber(), serverName));
        return requestBuilder;
    }
    public RequestBuilder addFirewallRule(String serverNameServerServiceResourceModel firewallRule){
        RequestBuilder requestBuilder = RequestBuilder.post();
        addAzureCommonHeaders(requestBuilder);
        requestBuilder.setUri(String.format(this..getContext().getAccountNumber(), serverName));
        requestBuilder.setEntity(new DaseinObjectToXmlEntity<ServerServiceResourceModel>(firewallRule));
        return requestBuilder;
    }
    public RequestBuilder listFirewallRules(String serveName){
        RequestBuilder requestBuilder = RequestBuilder.get();
        addAzureCommonHeaders(requestBuilder);
        requestBuilder.setUri(String.format(this..getContext().getAccountNumber(), serveName));
        return requestBuilder;
    }
    public RequestBuilder deleteFirewallRule(String serverNameString ruleNamethrows InternalException {
        RequestBuilder requestBuilder = RequestBuilder.delete();
        addAzureCommonHeaders(requestBuilder);
        requestBuilder.setUri(getEncodedUri(String.format(this..getContext().getAccountNumber(), serverNameruleName)));
        return requestBuilder;
    }
    private String getEncodedUri(String urlStringthrows InternalException {
        try {
            URL url = new URL(urlString);
            return new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(), url.getQuery(), url.getRef()).toString();
        } catch (Exception e) {
            throw new InternalException(e.getMessage());
        }
    }
    private void addAzureCommonHeaders(RequestBuilder requestBuilder){
        requestBuilder.addHeader("x-ms-version""2012-03-01");
        requestBuilder.addHeader("Content-Type""application/xml;charset=UTF-8");
    }
New to GrepCode? Check out our FAQ X