/*
 * Cloudera Manager API
 * <h1>Cloudera Manager API v50</h1>       <p>Introduced in Cloudera Manager 7.8.1</p>       <p><a href=\"http://www.cloudera.com/documentation.html\">Cloudera Product Documentation</a></p>
 *
 * OpenAPI spec version: 7.8.1
 * 
 *
 * NOTE: This class is auto generated by the swagger code generator program.
 * https://github.com/swagger-api/swagger-codegen.git
 * Do not edit the class manually.
 */


package com.cloudera.api.swagger;

import com.cloudera.api.swagger.client.ApiCallback;
import com.cloudera.api.swagger.client.ApiClient;
import com.cloudera.api.swagger.client.ApiException;
import com.cloudera.api.swagger.client.ApiResponse;
import com.cloudera.api.swagger.client.Configuration;
import com.cloudera.api.swagger.client.Pair;
import com.cloudera.api.swagger.client.ProgressRequestBody;
import com.cloudera.api.swagger.client.ProgressResponseBody;

import com.google.gson.reflect.TypeToken;

import java.io.IOException;


import com.cloudera.api.swagger.model.ApiCmPeer;
import com.cloudera.api.swagger.model.ApiCmPeerList;
import com.cloudera.api.swagger.model.ApiCommand;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class CmPeersResourceApi {
    private ApiClient apiClient;

    public CmPeersResourceApi() {
        this(Configuration.getDefaultApiClient());
    }

    public CmPeersResourceApi(ApiClient apiClient) {
        this.apiClient = apiClient;
    }

    public ApiClient getApiClient() {
        return apiClient;
    }

    public void setApiClient(ApiClient apiClient) {
        this.apiClient = apiClient;
    }

    /**
     * Build call for createPeer
     * @param body Peer to create (see above). (optional)
     * @param progressListener Progress listener
     * @param progressRequestListener Progress request listener
     * @return Call to execute
     * @throws ApiException If fail to serialize the request body object
     */
    public com.squareup.okhttp.Call createPeerCall(ApiCmPeer body, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
        Object localVarPostBody = body;
        
        // create path and map variables
        String localVarPath = "/cm/peers";

        List<Pair> localVarQueryParams = new ArrayList<Pair>();

        Map<String, String> localVarHeaderParams = new HashMap<String, String>();

        Map<String, Object> localVarFormParams = new HashMap<String, Object>();

        final String[] localVarAccepts = {
            "application/json"
        };
        final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
        if (localVarAccept != null) localVarHeaderParams.put("Accept", localVarAccept);

        final String[] localVarContentTypes = {
            "application/json"
        };
        final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes);
        localVarHeaderParams.put("Content-Type", localVarContentType);

        if(progressListener != null) {
            apiClient.getHttpClient().networkInterceptors().add(new com.squareup.okhttp.Interceptor() {
                @Override
                public com.squareup.okhttp.Response intercept(com.squareup.okhttp.Interceptor.Chain chain) throws IOException {
                    com.squareup.okhttp.Response originalResponse = chain.proceed(chain.request());
                    return originalResponse.newBuilder()
                    .body(new ProgressResponseBody(originalResponse.body(), progressListener))
                    .build();
                }
            });
        }

        String[] localVarAuthNames = new String[] { "basic" };
        return apiClient.buildCall(localVarPath, "POST", localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener);
    }
    
    @SuppressWarnings("rawtypes")
    private com.squareup.okhttp.Call createPeerValidateBeforeCall(ApiCmPeer body, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
        
        
        com.squareup.okhttp.Call call = createPeerCall(body, progressListener, progressRequestListener);
        return call;

        
        
        
        
    }

    /**
     * Create a new Cloudera Manager peer.
     * Create a new Cloudera Manager peer. &lt;p&gt; The remote server will be contacted so that a user can be created for use by the new peer. The &lt;i&gt;username&lt;/i&gt; and &lt;i&gt;password&lt;/i&gt; properties of the provided peer object should contain credentials of a valid admin user on the remote server. A timeout of 10 seconds is enforced when contacting the remote server. &lt;p&gt; It is recommended to run the remote server with TLS enabled, since creating and using peers involve transferring credentials over the network. &lt;p&gt; Available since API v3. Only available with Cloudera Manager Enterprise Edition. &lt;p&gt; Type field in ApiCmPeer is available since API v11. if not specified when making createPeer() call, &#39;REPLICATION&#39; type peer will be created.
     * @param body Peer to create (see above). (optional)
     * @return ApiCmPeer
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public ApiCmPeer createPeer(ApiCmPeer body) throws ApiException {
        ApiResponse<ApiCmPeer> resp = createPeerWithHttpInfo(body);
        return resp.getData();
    }

    /**
     * Create a new Cloudera Manager peer.
     * Create a new Cloudera Manager peer. &lt;p&gt; The remote server will be contacted so that a user can be created for use by the new peer. The &lt;i&gt;username&lt;/i&gt; and &lt;i&gt;password&lt;/i&gt; properties of the provided peer object should contain credentials of a valid admin user on the remote server. A timeout of 10 seconds is enforced when contacting the remote server. &lt;p&gt; It is recommended to run the remote server with TLS enabled, since creating and using peers involve transferring credentials over the network. &lt;p&gt; Available since API v3. Only available with Cloudera Manager Enterprise Edition. &lt;p&gt; Type field in ApiCmPeer is available since API v11. if not specified when making createPeer() call, &#39;REPLICATION&#39; type peer will be created.
     * @param body Peer to create (see above). (optional)
     * @return ApiResponse&lt;ApiCmPeer&gt;
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public ApiResponse<ApiCmPeer> createPeerWithHttpInfo(ApiCmPeer body) throws ApiException {
        com.squareup.okhttp.Call call = createPeerValidateBeforeCall(body, null, null);
        Type localVarReturnType = new TypeToken<ApiCmPeer>(){}.getType();
        return apiClient.execute(call, localVarReturnType);
    }

    /**
     * Create a new Cloudera Manager peer. (asynchronously)
     * Create a new Cloudera Manager peer. &lt;p&gt; The remote server will be contacted so that a user can be created for use by the new peer. The &lt;i&gt;username&lt;/i&gt; and &lt;i&gt;password&lt;/i&gt; properties of the provided peer object should contain credentials of a valid admin user on the remote server. A timeout of 10 seconds is enforced when contacting the remote server. &lt;p&gt; It is recommended to run the remote server with TLS enabled, since creating and using peers involve transferring credentials over the network. &lt;p&gt; Available since API v3. Only available with Cloudera Manager Enterprise Edition. &lt;p&gt; Type field in ApiCmPeer is available since API v11. if not specified when making createPeer() call, &#39;REPLICATION&#39; type peer will be created.
     * @param body Peer to create (see above). (optional)
     * @param callback The callback to be executed when the API call finishes
     * @return The request call
     * @throws ApiException If fail to process the API call, e.g. serializing the request body object
     */
    public com.squareup.okhttp.Call createPeerAsync(ApiCmPeer body, final ApiCallback<ApiCmPeer> callback) throws ApiException {

        ProgressResponseBody.ProgressListener progressListener = null;
        ProgressRequestBody.ProgressRequestListener progressRequestListener = null;

        if (callback != null) {
            progressListener = new ProgressResponseBody.ProgressListener() {
                @Override
                public void update(long bytesRead, long contentLength, boolean done) {
                    callback.onDownloadProgress(bytesRead, contentLength, done);
                }
            };

            progressRequestListener = new ProgressRequestBody.ProgressRequestListener() {
                @Override
                public void onRequestProgress(long bytesWritten, long contentLength, boolean done) {
                    callback.onUploadProgress(bytesWritten, contentLength, done);
                }
            };
        }

        com.squareup.okhttp.Call call = createPeerValidateBeforeCall(body, progressListener, progressRequestListener);
        Type localVarReturnType = new TypeToken<ApiCmPeer>(){}.getType();
        apiClient.executeAsync(call, localVarReturnType, callback);
        return call;
    }
    /**
     * Build call for deletePeer
     * @param peerName Name of peer to delete. (required)
     * @param type Type of peer to delete. If null, REPLICATION peer type will be deleted. (optional)
     * @param progressListener Progress listener
     * @param progressRequestListener Progress request listener
     * @return Call to execute
     * @throws ApiException If fail to serialize the request body object
     */
    public com.squareup.okhttp.Call deletePeerCall(String peerName, String type, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
        Object localVarPostBody = null;
        
        // create path and map variables
        String localVarPath = "/cm/peers/{peerName}"
            .replaceAll("\\{" + "peerName" + "\\}", apiClient.escapeString(peerName.toString()));

        List<Pair> localVarQueryParams = new ArrayList<Pair>();
        if (type != null)
        localVarQueryParams.addAll(apiClient.parameterToPairs("", "type", type));

        Map<String, String> localVarHeaderParams = new HashMap<String, String>();

        Map<String, Object> localVarFormParams = new HashMap<String, Object>();

        final String[] localVarAccepts = {
            "application/json"
        };
        final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
        if (localVarAccept != null) localVarHeaderParams.put("Accept", localVarAccept);

        final String[] localVarContentTypes = {
            
        };
        final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes);
        localVarHeaderParams.put("Content-Type", localVarContentType);

        if(progressListener != null) {
            apiClient.getHttpClient().networkInterceptors().add(new com.squareup.okhttp.Interceptor() {
                @Override
                public com.squareup.okhttp.Response intercept(com.squareup.okhttp.Interceptor.Chain chain) throws IOException {
                    com.squareup.okhttp.Response originalResponse = chain.proceed(chain.request());
                    return originalResponse.newBuilder()
                    .body(new ProgressResponseBody(originalResponse.body(), progressListener))
                    .build();
                }
            });
        }

        String[] localVarAuthNames = new String[] { "basic" };
        return apiClient.buildCall(localVarPath, "DELETE", localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener);
    }
    
    @SuppressWarnings("rawtypes")
    private com.squareup.okhttp.Call deletePeerValidateBeforeCall(String peerName, String type, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
        
        // verify the required parameter 'peerName' is set
        if (peerName == null) {
            throw new ApiException("Missing the required parameter 'peerName' when calling deletePeer(Async)");
        }
        
        
        com.squareup.okhttp.Call call = deletePeerCall(peerName, type, progressListener, progressRequestListener);
        return call;

        
        
        
        
    }

    /**
     * Delete Cloudera Manager peer.
     * Delete Cloudera Manager peer. &lt;p&gt; An attempt will be made to contact the peer server, so that the configured user can be deleted.. Errors while contacting the remote server are non-fatal. &lt;p&gt; Available since API v11. Only available with Cloudera Manager Enterprise Edition.
     * @param peerName Name of peer to delete. (required)
     * @param type Type of peer to delete. If null, REPLICATION peer type will be deleted. (optional)
     * @return ApiCmPeer
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public ApiCmPeer deletePeer(String peerName, String type) throws ApiException {
        ApiResponse<ApiCmPeer> resp = deletePeerWithHttpInfo(peerName, type);
        return resp.getData();
    }

    /**
     * Delete Cloudera Manager peer.
     * Delete Cloudera Manager peer. &lt;p&gt; An attempt will be made to contact the peer server, so that the configured user can be deleted.. Errors while contacting the remote server are non-fatal. &lt;p&gt; Available since API v11. Only available with Cloudera Manager Enterprise Edition.
     * @param peerName Name of peer to delete. (required)
     * @param type Type of peer to delete. If null, REPLICATION peer type will be deleted. (optional)
     * @return ApiResponse&lt;ApiCmPeer&gt;
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public ApiResponse<ApiCmPeer> deletePeerWithHttpInfo(String peerName, String type) throws ApiException {
        com.squareup.okhttp.Call call = deletePeerValidateBeforeCall(peerName, type, null, null);
        Type localVarReturnType = new TypeToken<ApiCmPeer>(){}.getType();
        return apiClient.execute(call, localVarReturnType);
    }

    /**
     * Delete Cloudera Manager peer. (asynchronously)
     * Delete Cloudera Manager peer. &lt;p&gt; An attempt will be made to contact the peer server, so that the configured user can be deleted.. Errors while contacting the remote server are non-fatal. &lt;p&gt; Available since API v11. Only available with Cloudera Manager Enterprise Edition.
     * @param peerName Name of peer to delete. (required)
     * @param type Type of peer to delete. If null, REPLICATION peer type will be deleted. (optional)
     * @param callback The callback to be executed when the API call finishes
     * @return The request call
     * @throws ApiException If fail to process the API call, e.g. serializing the request body object
     */
    public com.squareup.okhttp.Call deletePeerAsync(String peerName, String type, final ApiCallback<ApiCmPeer> callback) throws ApiException {

        ProgressResponseBody.ProgressListener progressListener = null;
        ProgressRequestBody.ProgressRequestListener progressRequestListener = null;

        if (callback != null) {
            progressListener = new ProgressResponseBody.ProgressListener() {
                @Override
                public void update(long bytesRead, long contentLength, boolean done) {
                    callback.onDownloadProgress(bytesRead, contentLength, done);
                }
            };

            progressRequestListener = new ProgressRequestBody.ProgressRequestListener() {
                @Override
                public void onRequestProgress(long bytesWritten, long contentLength, boolean done) {
                    callback.onUploadProgress(bytesWritten, contentLength, done);
                }
            };
        }

        com.squareup.okhttp.Call call = deletePeerValidateBeforeCall(peerName, type, progressListener, progressRequestListener);
        Type localVarReturnType = new TypeToken<ApiCmPeer>(){}.getType();
        apiClient.executeAsync(call, localVarReturnType, callback);
        return call;
    }
    /**
     * Build call for listPeers
     * @param progressListener Progress listener
     * @param progressRequestListener Progress request listener
     * @return Call to execute
     * @throws ApiException If fail to serialize the request body object
     */
    public com.squareup.okhttp.Call listPeersCall(final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
        Object localVarPostBody = null;
        
        // create path and map variables
        String localVarPath = "/cm/peers";

        List<Pair> localVarQueryParams = new ArrayList<Pair>();

        Map<String, String> localVarHeaderParams = new HashMap<String, String>();

        Map<String, Object> localVarFormParams = new HashMap<String, Object>();

        final String[] localVarAccepts = {
            "application/json"
        };
        final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
        if (localVarAccept != null) localVarHeaderParams.put("Accept", localVarAccept);

        final String[] localVarContentTypes = {
            
        };
        final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes);
        localVarHeaderParams.put("Content-Type", localVarContentType);

        if(progressListener != null) {
            apiClient.getHttpClient().networkInterceptors().add(new com.squareup.okhttp.Interceptor() {
                @Override
                public com.squareup.okhttp.Response intercept(com.squareup.okhttp.Interceptor.Chain chain) throws IOException {
                    com.squareup.okhttp.Response originalResponse = chain.proceed(chain.request());
                    return originalResponse.newBuilder()
                    .body(new ProgressResponseBody(originalResponse.body(), progressListener))
                    .build();
                }
            });
        }

        String[] localVarAuthNames = new String[] { "basic" };
        return apiClient.buildCall(localVarPath, "GET", localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener);
    }
    
    @SuppressWarnings("rawtypes")
    private com.squareup.okhttp.Call listPeersValidateBeforeCall(final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
        
        
        com.squareup.okhttp.Call call = listPeersCall(progressListener, progressRequestListener);
        return call;

        
        
        
        
    }

    /**
     * Retrieves all configured Cloudera Manager peers.
     * Retrieves all configured Cloudera Manager peers. &lt;p&gt; Available since API v3. Only available with Cloudera Manager Enterprise Edition. &lt;p&gt; When accessed via API version before v11, only REPLICATION type peers will be returned.
     * @return ApiCmPeerList
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public ApiCmPeerList listPeers() throws ApiException {
        ApiResponse<ApiCmPeerList> resp = listPeersWithHttpInfo();
        return resp.getData();
    }

    /**
     * Retrieves all configured Cloudera Manager peers.
     * Retrieves all configured Cloudera Manager peers. &lt;p&gt; Available since API v3. Only available with Cloudera Manager Enterprise Edition. &lt;p&gt; When accessed via API version before v11, only REPLICATION type peers will be returned.
     * @return ApiResponse&lt;ApiCmPeerList&gt;
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public ApiResponse<ApiCmPeerList> listPeersWithHttpInfo() throws ApiException {
        com.squareup.okhttp.Call call = listPeersValidateBeforeCall(null, null);
        Type localVarReturnType = new TypeToken<ApiCmPeerList>(){}.getType();
        return apiClient.execute(call, localVarReturnType);
    }

    /**
     * Retrieves all configured Cloudera Manager peers. (asynchronously)
     * Retrieves all configured Cloudera Manager peers. &lt;p&gt; Available since API v3. Only available with Cloudera Manager Enterprise Edition. &lt;p&gt; When accessed via API version before v11, only REPLICATION type peers will be returned.
     * @param callback The callback to be executed when the API call finishes
     * @return The request call
     * @throws ApiException If fail to process the API call, e.g. serializing the request body object
     */
    public com.squareup.okhttp.Call listPeersAsync(final ApiCallback<ApiCmPeerList> callback) throws ApiException {

        ProgressResponseBody.ProgressListener progressListener = null;
        ProgressRequestBody.ProgressRequestListener progressRequestListener = null;

        if (callback != null) {
            progressListener = new ProgressResponseBody.ProgressListener() {
                @Override
                public void update(long bytesRead, long contentLength, boolean done) {
                    callback.onDownloadProgress(bytesRead, contentLength, done);
                }
            };

            progressRequestListener = new ProgressRequestBody.ProgressRequestListener() {
                @Override
                public void onRequestProgress(long bytesWritten, long contentLength, boolean done) {
                    callback.onUploadProgress(bytesWritten, contentLength, done);
                }
            };
        }

        com.squareup.okhttp.Call call = listPeersValidateBeforeCall(progressListener, progressRequestListener);
        Type localVarReturnType = new TypeToken<ApiCmPeerList>(){}.getType();
        apiClient.executeAsync(call, localVarReturnType, callback);
        return call;
    }
    /**
     * Build call for readPeer
     * @param peerName Name of peer to retrieve. (required)
     * @param type Type of peer to retrieve. If null, REPLICATION peer type will be returned. (optional)
     * @param progressListener Progress listener
     * @param progressRequestListener Progress request listener
     * @return Call to execute
     * @throws ApiException If fail to serialize the request body object
     */
    public com.squareup.okhttp.Call readPeerCall(String peerName, String type, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
        Object localVarPostBody = null;
        
        // create path and map variables
        String localVarPath = "/cm/peers/{peerName}"
            .replaceAll("\\{" + "peerName" + "\\}", apiClient.escapeString(peerName.toString()));

        List<Pair> localVarQueryParams = new ArrayList<Pair>();
        if (type != null)
        localVarQueryParams.addAll(apiClient.parameterToPairs("", "type", type));

        Map<String, String> localVarHeaderParams = new HashMap<String, String>();

        Map<String, Object> localVarFormParams = new HashMap<String, Object>();

        final String[] localVarAccepts = {
            "application/json"
        };
        final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
        if (localVarAccept != null) localVarHeaderParams.put("Accept", localVarAccept);

        final String[] localVarContentTypes = {
            
        };
        final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes);
        localVarHeaderParams.put("Content-Type", localVarContentType);

        if(progressListener != null) {
            apiClient.getHttpClient().networkInterceptors().add(new com.squareup.okhttp.Interceptor() {
                @Override
                public com.squareup.okhttp.Response intercept(com.squareup.okhttp.Interceptor.Chain chain) throws IOException {
                    com.squareup.okhttp.Response originalResponse = chain.proceed(chain.request());
                    return originalResponse.newBuilder()
                    .body(new ProgressResponseBody(originalResponse.body(), progressListener))
                    .build();
                }
            });
        }

        String[] localVarAuthNames = new String[] { "basic" };
        return apiClient.buildCall(localVarPath, "GET", localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener);
    }
    
    @SuppressWarnings("rawtypes")
    private com.squareup.okhttp.Call readPeerValidateBeforeCall(String peerName, String type, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
        
        // verify the required parameter 'peerName' is set
        if (peerName == null) {
            throw new ApiException("Missing the required parameter 'peerName' when calling readPeer(Async)");
        }
        
        
        com.squareup.okhttp.Call call = readPeerCall(peerName, type, progressListener, progressRequestListener);
        return call;

        
        
        
        
    }

    /**
     * Fetch information about an existing Cloudera Manager peer.
     * Fetch information about an existing Cloudera Manager peer. &lt;p&gt; Available since API v11. Only available with Cloudera Manager Enterprise Edition.
     * @param peerName Name of peer to retrieve. (required)
     * @param type Type of peer to retrieve. If null, REPLICATION peer type will be returned. (optional)
     * @return ApiCmPeer
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public ApiCmPeer readPeer(String peerName, String type) throws ApiException {
        ApiResponse<ApiCmPeer> resp = readPeerWithHttpInfo(peerName, type);
        return resp.getData();
    }

    /**
     * Fetch information about an existing Cloudera Manager peer.
     * Fetch information about an existing Cloudera Manager peer. &lt;p&gt; Available since API v11. Only available with Cloudera Manager Enterprise Edition.
     * @param peerName Name of peer to retrieve. (required)
     * @param type Type of peer to retrieve. If null, REPLICATION peer type will be returned. (optional)
     * @return ApiResponse&lt;ApiCmPeer&gt;
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public ApiResponse<ApiCmPeer> readPeerWithHttpInfo(String peerName, String type) throws ApiException {
        com.squareup.okhttp.Call call = readPeerValidateBeforeCall(peerName, type, null, null);
        Type localVarReturnType = new TypeToken<ApiCmPeer>(){}.getType();
        return apiClient.execute(call, localVarReturnType);
    }

    /**
     * Fetch information about an existing Cloudera Manager peer. (asynchronously)
     * Fetch information about an existing Cloudera Manager peer. &lt;p&gt; Available since API v11. Only available with Cloudera Manager Enterprise Edition.
     * @param peerName Name of peer to retrieve. (required)
     * @param type Type of peer to retrieve. If null, REPLICATION peer type will be returned. (optional)
     * @param callback The callback to be executed when the API call finishes
     * @return The request call
     * @throws ApiException If fail to process the API call, e.g. serializing the request body object
     */
    public com.squareup.okhttp.Call readPeerAsync(String peerName, String type, final ApiCallback<ApiCmPeer> callback) throws ApiException {

        ProgressResponseBody.ProgressListener progressListener = null;
        ProgressRequestBody.ProgressRequestListener progressRequestListener = null;

        if (callback != null) {
            progressListener = new ProgressResponseBody.ProgressListener() {
                @Override
                public void update(long bytesRead, long contentLength, boolean done) {
                    callback.onDownloadProgress(bytesRead, contentLength, done);
                }
            };

            progressRequestListener = new ProgressRequestBody.ProgressRequestListener() {
                @Override
                public void onRequestProgress(long bytesWritten, long contentLength, boolean done) {
                    callback.onUploadProgress(bytesWritten, contentLength, done);
                }
            };
        }

        com.squareup.okhttp.Call call = readPeerValidateBeforeCall(peerName, type, progressListener, progressRequestListener);
        Type localVarReturnType = new TypeToken<ApiCmPeer>(){}.getType();
        apiClient.executeAsync(call, localVarReturnType, callback);
        return call;
    }
    /**
     * Build call for testPeer
     * @param peerName Name of peer to test. (required)
     * @param type Type of peer to test. If null, REPLICATION peer type will be tested. (optional)
     * @param progressListener Progress listener
     * @param progressRequestListener Progress request listener
     * @return Call to execute
     * @throws ApiException If fail to serialize the request body object
     */
    public com.squareup.okhttp.Call testPeerCall(String peerName, String type, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
        Object localVarPostBody = null;
        
        // create path and map variables
        String localVarPath = "/cm/peers/{peerName}/commands/test"
            .replaceAll("\\{" + "peerName" + "\\}", apiClient.escapeString(peerName.toString()));

        List<Pair> localVarQueryParams = new ArrayList<Pair>();
        if (type != null)
        localVarQueryParams.addAll(apiClient.parameterToPairs("", "type", type));

        Map<String, String> localVarHeaderParams = new HashMap<String, String>();

        Map<String, Object> localVarFormParams = new HashMap<String, Object>();

        final String[] localVarAccepts = {
            "application/json"
        };
        final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
        if (localVarAccept != null) localVarHeaderParams.put("Accept", localVarAccept);

        final String[] localVarContentTypes = {
            
        };
        final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes);
        localVarHeaderParams.put("Content-Type", localVarContentType);

        if(progressListener != null) {
            apiClient.getHttpClient().networkInterceptors().add(new com.squareup.okhttp.Interceptor() {
                @Override
                public com.squareup.okhttp.Response intercept(com.squareup.okhttp.Interceptor.Chain chain) throws IOException {
                    com.squareup.okhttp.Response originalResponse = chain.proceed(chain.request());
                    return originalResponse.newBuilder()
                    .body(new ProgressResponseBody(originalResponse.body(), progressListener))
                    .build();
                }
            });
        }

        String[] localVarAuthNames = new String[] { "basic" };
        return apiClient.buildCall(localVarPath, "POST", localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener);
    }
    
    @SuppressWarnings("rawtypes")
    private com.squareup.okhttp.Call testPeerValidateBeforeCall(String peerName, String type, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
        
        // verify the required parameter 'peerName' is set
        if (peerName == null) {
            throw new ApiException("Missing the required parameter 'peerName' when calling testPeer(Async)");
        }
        
        
        com.squareup.okhttp.Call call = testPeerCall(peerName, type, progressListener, progressRequestListener);
        return call;

        
        
        
        
    }

    /**
     * Test the connectivity of a peer.
     * Test the connectivity of a peer. &lt;p&gt; Available since API v11. Only available with Cloudera Manager Enterprise Edition.
     * @param peerName Name of peer to test. (required)
     * @param type Type of peer to test. If null, REPLICATION peer type will be tested. (optional)
     * @return ApiCommand
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public ApiCommand testPeer(String peerName, String type) throws ApiException {
        ApiResponse<ApiCommand> resp = testPeerWithHttpInfo(peerName, type);
        return resp.getData();
    }

    /**
     * Test the connectivity of a peer.
     * Test the connectivity of a peer. &lt;p&gt; Available since API v11. Only available with Cloudera Manager Enterprise Edition.
     * @param peerName Name of peer to test. (required)
     * @param type Type of peer to test. If null, REPLICATION peer type will be tested. (optional)
     * @return ApiResponse&lt;ApiCommand&gt;
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public ApiResponse<ApiCommand> testPeerWithHttpInfo(String peerName, String type) throws ApiException {
        com.squareup.okhttp.Call call = testPeerValidateBeforeCall(peerName, type, null, null);
        Type localVarReturnType = new TypeToken<ApiCommand>(){}.getType();
        return apiClient.execute(call, localVarReturnType);
    }

    /**
     * Test the connectivity of a peer. (asynchronously)
     * Test the connectivity of a peer. &lt;p&gt; Available since API v11. Only available with Cloudera Manager Enterprise Edition.
     * @param peerName Name of peer to test. (required)
     * @param type Type of peer to test. If null, REPLICATION peer type will be tested. (optional)
     * @param callback The callback to be executed when the API call finishes
     * @return The request call
     * @throws ApiException If fail to process the API call, e.g. serializing the request body object
     */
    public com.squareup.okhttp.Call testPeerAsync(String peerName, String type, final ApiCallback<ApiCommand> callback) throws ApiException {

        ProgressResponseBody.ProgressListener progressListener = null;
        ProgressRequestBody.ProgressRequestListener progressRequestListener = null;

        if (callback != null) {
            progressListener = new ProgressResponseBody.ProgressListener() {
                @Override
                public void update(long bytesRead, long contentLength, boolean done) {
                    callback.onDownloadProgress(bytesRead, contentLength, done);
                }
            };

            progressRequestListener = new ProgressRequestBody.ProgressRequestListener() {
                @Override
                public void onRequestProgress(long bytesWritten, long contentLength, boolean done) {
                    callback.onUploadProgress(bytesWritten, contentLength, done);
                }
            };
        }

        com.squareup.okhttp.Call call = testPeerValidateBeforeCall(peerName, type, progressListener, progressRequestListener);
        Type localVarReturnType = new TypeToken<ApiCommand>(){}.getType();
        apiClient.executeAsync(call, localVarReturnType, callback);
        return call;
    }
    /**
     * Build call for updatePeer
     * @param peerName Name of peer to update. (required)
     * @param body Updated peer information. (optional)
     * @param progressListener Progress listener
     * @param progressRequestListener Progress request listener
     * @return Call to execute
     * @throws ApiException If fail to serialize the request body object
     */
    public com.squareup.okhttp.Call updatePeerCall(String peerName, ApiCmPeer body, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
        Object localVarPostBody = body;
        
        // create path and map variables
        String localVarPath = "/cm/peers/{peerName}"
            .replaceAll("\\{" + "peerName" + "\\}", apiClient.escapeString(peerName.toString()));

        List<Pair> localVarQueryParams = new ArrayList<Pair>();

        Map<String, String> localVarHeaderParams = new HashMap<String, String>();

        Map<String, Object> localVarFormParams = new HashMap<String, Object>();

        final String[] localVarAccepts = {
            "application/json"
        };
        final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
        if (localVarAccept != null) localVarHeaderParams.put("Accept", localVarAccept);

        final String[] localVarContentTypes = {
            "application/json"
        };
        final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes);
        localVarHeaderParams.put("Content-Type", localVarContentType);

        if(progressListener != null) {
            apiClient.getHttpClient().networkInterceptors().add(new com.squareup.okhttp.Interceptor() {
                @Override
                public com.squareup.okhttp.Response intercept(com.squareup.okhttp.Interceptor.Chain chain) throws IOException {
                    com.squareup.okhttp.Response originalResponse = chain.proceed(chain.request());
                    return originalResponse.newBuilder()
                    .body(new ProgressResponseBody(originalResponse.body(), progressListener))
                    .build();
                }
            });
        }

        String[] localVarAuthNames = new String[] { "basic" };
        return apiClient.buildCall(localVarPath, "PUT", localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener);
    }
    
    @SuppressWarnings("rawtypes")
    private com.squareup.okhttp.Call updatePeerValidateBeforeCall(String peerName, ApiCmPeer body, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
        
        // verify the required parameter 'peerName' is set
        if (peerName == null) {
            throw new ApiException("Missing the required parameter 'peerName' when calling updatePeer(Async)");
        }
        
        
        com.squareup.okhttp.Call call = updatePeerCall(peerName, body, progressListener, progressRequestListener);
        return call;

        
        
        
        
    }

    /**
     * Update information for a Cloudera Manager peer.
     * Update information for a Cloudera Manager peer. &lt;p&gt; In administrator credentials are provided in the peer information, they will be used to establish new credentials with the remote server. This can be used in case the old credentials are not working anymore. An attempt will be made to delete the old credentials if new ones are successfully created. &lt;p&gt; If changing the peer&#39;s URL, an attempt will be made to contact the old Cloudera Manager to delete the existing credentials. &lt;p&gt; Available since API v3. Only available with Cloudera Manager Enterprise Edition.
     * @param peerName Name of peer to update. (required)
     * @param body Updated peer information. (optional)
     * @return ApiCmPeer
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public ApiCmPeer updatePeer(String peerName, ApiCmPeer body) throws ApiException {
        ApiResponse<ApiCmPeer> resp = updatePeerWithHttpInfo(peerName, body);
        return resp.getData();
    }

    /**
     * Update information for a Cloudera Manager peer.
     * Update information for a Cloudera Manager peer. &lt;p&gt; In administrator credentials are provided in the peer information, they will be used to establish new credentials with the remote server. This can be used in case the old credentials are not working anymore. An attempt will be made to delete the old credentials if new ones are successfully created. &lt;p&gt; If changing the peer&#39;s URL, an attempt will be made to contact the old Cloudera Manager to delete the existing credentials. &lt;p&gt; Available since API v3. Only available with Cloudera Manager Enterprise Edition.
     * @param peerName Name of peer to update. (required)
     * @param body Updated peer information. (optional)
     * @return ApiResponse&lt;ApiCmPeer&gt;
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     */
    public ApiResponse<ApiCmPeer> updatePeerWithHttpInfo(String peerName, ApiCmPeer body) throws ApiException {
        com.squareup.okhttp.Call call = updatePeerValidateBeforeCall(peerName, body, null, null);
        Type localVarReturnType = new TypeToken<ApiCmPeer>(){}.getType();
        return apiClient.execute(call, localVarReturnType);
    }

    /**
     * Update information for a Cloudera Manager peer. (asynchronously)
     * Update information for a Cloudera Manager peer. &lt;p&gt; In administrator credentials are provided in the peer information, they will be used to establish new credentials with the remote server. This can be used in case the old credentials are not working anymore. An attempt will be made to delete the old credentials if new ones are successfully created. &lt;p&gt; If changing the peer&#39;s URL, an attempt will be made to contact the old Cloudera Manager to delete the existing credentials. &lt;p&gt; Available since API v3. Only available with Cloudera Manager Enterprise Edition.
     * @param peerName Name of peer to update. (required)
     * @param body Updated peer information. (optional)
     * @param callback The callback to be executed when the API call finishes
     * @return The request call
     * @throws ApiException If fail to process the API call, e.g. serializing the request body object
     */
    public com.squareup.okhttp.Call updatePeerAsync(String peerName, ApiCmPeer body, final ApiCallback<ApiCmPeer> callback) throws ApiException {

        ProgressResponseBody.ProgressListener progressListener = null;
        ProgressRequestBody.ProgressRequestListener progressRequestListener = null;

        if (callback != null) {
            progressListener = new ProgressResponseBody.ProgressListener() {
                @Override
                public void update(long bytesRead, long contentLength, boolean done) {
                    callback.onDownloadProgress(bytesRead, contentLength, done);
                }
            };

            progressRequestListener = new ProgressRequestBody.ProgressRequestListener() {
                @Override
                public void onRequestProgress(long bytesWritten, long contentLength, boolean done) {
                    callback.onUploadProgress(bytesWritten, contentLength, done);
                }
            };
        }

        com.squareup.okhttp.Call call = updatePeerValidateBeforeCall(peerName, body, progressListener, progressRequestListener);
        Type localVarReturnType = new TypeToken<ApiCmPeer>(){}.getType();
        apiClient.executeAsync(call, localVarReturnType, callback);
        return call;
    }
}
