import { Injectable } from '@angular/core' ; import { MessageService , MessageSeverity } from './message.service' ; import { HttpClient , HttpErrorResponse } from '@angular/common/http' ; import { HealthStateFilterFlags , IClusterHealthChunkQueryDescription } from '../Models/HealthChunkRawDataTypes' ; import { IResponseMessageHandler , ResponseMessageHandlers } from '../Common/ResponseMessageHandlers' ; import { Observable , of , throwError } from 'rxjs' ; import { IRawCollection , IRawClusterManifest , IRawClusterHealth , IRawClusterUpgradeProgress , IRawClusterLoadInformation , IRawDeployedContainerOnNetwork , IRawNode , IRawBackupPolicy , IRawApplicationBackupConfigurationInfo , IRawServiceBackupConfigurationInfo , IRawBackupProgressInfo , IRawRestoreProgressInfo , IRawPartitionBackupConfigurationInfo , IRawPartitionBackup , IRawNodeHealth , IRawNodeLoadInformation , IRawDeployedApplication , IRawApplicationHealth , IRawDeployedServicePackage , IRawDeployedServicePackageHealth , IRawServiceManifest , IRawDeployedReplica , IRawServiceType , IRawDeployedCodePackage , IRawContainerLogs , IRawDeployedReplicaDetail , IRawApplicationType , IRawApplicationManifest , IRawApplication , IRawService , IRawCreateServiceDescription , IRawCreateServiceFromTemplateDescription , IRawUpdateServiceDescription , IRawServiceDescription , IRawServiceHealth , IRawApplicationUpgradeProgress , IRawCreateComposeDeploymentDescription , IRawPartition , IRawPartitionHealth , IRawPartitionLoadInformation , IRawReplicaOnPartition , IRawReplicaHealth , IRawImageStoreContent , IRawStoreFolderSize , IRawClusterVersion , IRawList , IRawAadMetadata , IRawStorage , IRawRepairTask , IRawServiceNameInfo , IRawApplicationNameInfo , IRawBackupEntity } from '../Models/RawDataTypes' ; import { mergeMap , map , catchError , finalize , skip } from 'rxjs/operators' ; import { Application } from '../Models/DataModels/Application' ; import { Service } from '../Models/DataModels/Service' ; import { Partition } from '../Models/DataModels/Partition' ; import { ClusterEvent , NodeEvent , ApplicationEvent , ServiceEvent , PartitionEvent , ReplicaEvent , FabricEvent , EventsResponseAdapter , FabricEventBase } from '../Models/eventstore/Events' ; import { StandaloneIntegration } from '../Common/StandaloneIntegration' ; import { AadMetadata } from '../Models/DataModels/Aad' ; import { environment } from 'src/environments/environment' ; import { IRequest , NetworkDebugger } from '../Models/DataModels/networkDebugger' ; @ Injectable ( { providedIn : 'root' } ) export class RestClientService { constructor ( private httpClient , private message ) { } private static defaultApiVersion = '3.0' ; private static apiVersion40 = '4.0' ; private static apiVersion60 = '6.0' ; private static apiVersion64 = '6.4' ; private static apiVersion65 = '6.5' ; private static apiVersion72 = '7.2' ; private static apiVersion80 = '8.0' ; private static apiVersion82 = '8.2' ; private cacheAllowanceToken : number = Date . now ( ) . valueOf ( ) ; public networkDebugger : NetworkDebugger = new NetworkDebugger ( ) ; public invalidateBrowserRestResponseCache ( ) { this . cacheAllowanceToken = Date . now ( ) . valueOf ( ) ; } public getClusterHealth ( eventsHealthStateFilter = HealthStateFilterFlags . Default , nodesHealthStateFilter = HealthStateFilterFlags . Default , applicationsHealthStateFilter = HealthStateFilterFlags . Default , messageHandler ? ) { const url = `$/GetClusterHealth?NodesHealthStateFilter=${ nodesHealthStateFilter }` + `&ApplicationsHealthStateFilter=${ applicationsHealthStateFilter }&EventsHealthStateFilter=${ eventsHealthStateFilter }` ; return this . get ( this . getApiUrl ( url ) , 'Get cluster health' , messageHandler ) ; } public getClusterManifest ( messageHandler ? ) { return this . get ( this . getApiUrl ( '$/GetClusterManifest' ) , 'Get cluster manifest' , messageHandler ) ; } public getClusterUpgradeProgress ( messageHandler ? ) { return this . get ( this . getApiUrl ( '$/GetUpgradeProgress' , RestClientService . apiVersion82 ) , 'Get cluster upgrade progress' , messageHandler ) ; } public getClusterLoadInformation ( messageHandler ? ) { return this . get ( this . getApiUrl ( '$/GetLoadInformation' ) , 'Get cluster load information' , messageHandler ) ; } public getClusterHealthChunk ( healthDescriptor , messageHandler ? ) { return this . post ( this . getApiUrl ( '$/GetClusterHealthChunk' ) , 'Get cluster health chunk' , healthDescriptor , messageHandler ) ; } public getDeployedContainersOnNetwork ( networkName , nodeName , messageHandler ? ) { const url = 'Nodes/' + encodeURIComponent ( nodeName ) + '/$/GetNetworks/' + encodeURIComponent ( networkName ) + '/$/GetCodePackages' ; return this . getFullCollection < IRawDeployedContainerOnNetwork > ( url , 'Get containers on network' , RestClientService . apiVersion60 ) ; } public getNodes ( messageHandler ? ) { return this . getFullCollection < IRawNode > ( 'Nodes/' , 'Get nodes' ) ; } public getNode ( nodeName , messageHandler ? ) { const url = 'Nodes/' + encodeURIComponent ( nodeName ) + '/' ; return this . get ( this . getApiUrl ( url ) , 'Get node' , messageHandler ) ; } public getAADmetadata ( messageHandler ? ) { const url = '$/GetAadMetadata/' ; return this . get < IRawAadMetadata > ( this . getApiUrl ( url , RestClientService . apiVersion60 ) , 'Get aadmetadata' , messageHandler ) . pipe ( map ( data => new AadMetadata ( data ) ) ) ; } public getBackupPolicies ( messageHandler ? ) { return this . getFullCollection < IRawBackupPolicy > ( 'BackupRestore/BackupPolicies/' , 'Get backup Policies' , RestClientService . apiVersion64 ) ; } public getApplicationBackupConfigurationInfoCollection ( applicationId , messageHandler ? ) { return this . getFullCollection < IRawApplicationBackupConfigurationInfo > ( 'Applications/' + encodeURIComponent ( applicationId ) + '/$/GetBackupConfigurationInfo' , 'Gets the application backup configuration information' , RestClientService . apiVersion64 , messageHandler ) ; } public getServiceBackupConfigurationInfoCollection ( serviceId , messageHandler ? ) { return this . getFullCollection < IRawServiceBackupConfigurationInfo > ( 'Services/' + encodeURIComponent ( serviceId ) + '/$/GetBackupConfigurationInfo' , 'Gets the application backup configuration information' , RestClientService . apiVersion64 , messageHandler ) ; } public getPartitionBackupProgress ( partitionId , messageHandler ? ) { return this . get ( this . getApiUrl ( 'Partitions/' + encodeURIComponent ( partitionId ) + '/$/GetBackupProgress' , RestClientService . apiVersion64 ) , 'Gets the partition backup progress' , messageHandler ) ; } public getPartitionRestoreProgress ( partitionId , messageHandler ? ) { return this . get ( this . getApiUrl ( 'Partitions/' + encodeURIComponent ( partitionId ) + '/$/GetRestoreProgress' , RestClientService . apiVersion64 ) , 'Gets the partition restore progress' , messageHandler ) ; } public getPartitionBackupConfigurationInfo ( partitionId , messageHandler ? ) { return this . get ( this . getApiUrl ( 'Partitions/' + encodeURIComponent ( partitionId ) + '/$/GetBackupConfigurationInfo' , RestClientService . apiVersion64 ) , 'Gets the partition backup configuration information' , messageHandler ) ; } public getLatestPartitionBackup ( partitionId , messageHandler ? ) { return this . getFullCollection2 < IRawPartitionBackup > ( 'Partitions/' + encodeURIComponent ( partitionId ) + '/$/GetBackups' , 'Gets the latest partition backup' , RestClientService . apiVersion64 , messageHandler , undefined , undefined , undefined , undefined , true ) ; } public getPartitionBackupList ( partitionId , messageHandler ? , startDate ? , endDate ? , maxResults ? ) { return this . getFullCollection2 < IRawPartitionBackup > ( 'Partitions/' + encodeURIComponent ( partitionId ) + '/$/GetBackups' , 'Gets the partition backup list' , RestClientService . apiVersion64 , messageHandler , undefined , startDate , endDate , maxResults ) ; } public getBackupPolicy ( backupName , messageHandler ? ) { const url = 'BackupRestore/BackupPolicies/' + encodeURIComponent ( backupName ) + '/' ; return this . get ( this . getApiUrl ( url , RestClientService . apiVersion64 ) , 'Get backup policy' , messageHandler ) ; } public getNodeHealth ( nodeName , eventsHealthStateFilter = HealthStateFilterFlags . Default , messageHandler ? ) { const url = `Nodes/${ encodeURIComponent ( nodeName ) }/$/GetHealth?EventsHealthStateFilter=${ eventsHealthStateFilter }` ; return this . get ( this . getApiUrl ( url ) , 'Get node health' , messageHandler ) ; } public getNodeLoadInformation ( nodeName , messageHandler ? ) { const url = 'Nodes/' + encodeURIComponent ( nodeName ) + '/$/GetLoadInformation' ; return this . get ( this . getApiUrl ( url ) , 'Get node load information' , messageHandler ) ; } public restartNode ( nodeName , nodeInstanceId , messageHandler ? ) { const url = 'Nodes/' + encodeURIComponent ( nodeName ) + '/$/Restart' ; const body = { NodeInstanceId : nodeInstanceId } ; return this . post ( this . getApiUrl ( url ) , 'Node restart' , body , messageHandler ) ; } public getDeployedApplications ( nodeName , messageHandler ? ) { const url = 'Nodes/' + encodeURIComponent ( nodeName ) + '/$/GetApplications' ; return this . get ( this . getApiUrl ( url ) , 'Get applications' , messageHandler ) ; } public getDeployedApplication ( nodeName , applicationId , messageHandler ? ) { const url = 'Nodes/' + encodeURIComponent ( nodeName ) + '/$/GetApplications/' + encodeURIComponent ( applicationId ) ; return this . get ( this . getApiUrl ( url ) , 'Get deployed applications' , messageHandler ) ; } public getDeployedApplicationHealth ( nodeName , applicationId , eventsHealthStateFilter = HealthStateFilterFlags . Default , deployedServicePackagesHealthStateFilter = HealthStateFilterFlags . Default , messageHandler ? ) { const url = `Nodes/${ encodeURIComponent ( nodeName ) }/$/GetApplications/${ encodeURIComponent ( applicationId ) }/$/GetHealth` + `?EventsHealthStateFilter=${ eventsHealthStateFilter }&DeployedServicePackagesHealthStateFilter=${ deployedServicePackagesHealthStateFilter }` ; return this . get ( this . getApiUrl ( url ) , 'Get application health' , messageHandler ) ; } public getDeployedServicePackages ( nodeName , applicationId , messageHandler ? ) { const url = 'Nodes/' + encodeURIComponent ( nodeName ) + '/$/GetApplications/' + encodeURIComponent ( applicationId ) + '/$/GetServicePackages' ; return this . get ( this . getApiUrl ( url ) , 'Get deployed service packages' , messageHandler ) ; } public getDeployedServicePackage ( nodeName , applicationId , servicePackageName , messageHandler ? ) { const url = 'Nodes/' + encodeURIComponent ( nodeName ) + '/$/GetApplications/' + encodeURIComponent ( applicationId ) + '/$/GetServicePackages/' + encodeURIComponent ( servicePackageName ) ; return this . get ( this . getApiUrl ( url ) , 'Get deployed service package on application' , messageHandler ) ; } public getDeployedServicePackageHealth ( nodeName , applicationId , servicePackageName , servicePackageActivationId , eventsHealthStateFilter = HealthStateFilterFlags . Default , messageHandler ? ) { const url = `Nodes/${ encodeURIComponent ( nodeName ) }/$/GetApplications/${ encodeURIComponent ( applicationId ) }` + `/$/GetServicePackages/${ encodeURI ( servicePackageName ) }` + `/$/GetHealth?EventsHealthStateFilter=${ eventsHealthStateFilter }` + ( servicePackageActivationId ? `&ServicePackageActivationId=${ servicePackageActivationId }` : '' ) ; return this . get ( this . getApiUrl ( url ) , 'Get deployed service package health' , messageHandler ) ; } public getServiceManifest ( appTypeName , appTypeVersion , serviceManifestName , messageHandler ? ) { const url = 'ApplicationTypes/' + encodeURIComponent ( appTypeName ) + '/$/GetServiceManifest' ; const formedUrl = this . getApiUrl ( url ) + '&ApplicationTypeVersion=' + encodeURIComponent ( appTypeVersion ) + '&ServiceManifestName=' + encodeURIComponent ( serviceManifestName ) ; return this . get ( formedUrl , 'Get service manifest for application type' , messageHandler ) ; } public getServiceTypes ( appTypeName , appTypeVersion , messageHandler ? ) { const url = 'ApplicationTypes/' + encodeURIComponent ( appTypeName ) + '/$/GetServiceTypes?ApplicationTypeVersion=' + encodeURIComponent ( appTypeVersion ) ; const formedUrl = this . getApiUrl ( url ) ; return this . get ( formedUrl , 'Get service types for application type' , messageHandler ) ; } public getDeployedReplicas ( nodeName , applicationId , servicePackageName , messageHandler ? ) { const url = 'Nodes/' + encodeURIComponent ( nodeName ) + '/$/GetApplications/' + encodeURIComponent ( applicationId ) + '/$/GetReplicas' ; const formedUrl = this . getApiUrl ( url ) + '&ServiceManifestName=' + encodeURIComponent ( servicePackageName ) ; return this . get ( formedUrl , 'Get replicas on service' , messageHandler ) ; } public getDeployedCodePackages ( nodeName , applicationId , servicePackageName , messageHandler ? ) { const url = 'Nodes/' + encodeURIComponent ( nodeName ) + '/$/GetApplications/' + encodeURIComponent ( applicationId ) + '/$/GetCodePackages' ; const formedUrl = this . getApiUrl ( url ) + '&ServiceManifestName=' + encodeURIComponent ( servicePackageName ) ; return this . get ( formedUrl , 'Get deployed code packages' , messageHandler ) ; } public getDeployedCodePackage ( nodeName , applicationId , servicePackageName , codePackageName , messageHandler ? ) { const url = 'Nodes/' + encodeURIComponent ( nodeName ) + '/$/GetApplications/' + encodeURIComponent ( applicationId ) + '/$/GetCodePackages' ; const formedUrl = this . getApiUrl ( url ) + '&ServiceManifestName=' + encodeURIComponent ( servicePackageName ) + '&CodePackageName=' + encodeURIComponent ( codePackageName ) ; return this . get ( formedUrl , 'Get deployed code package' , messageHandler ) ; } public getDeployedContainerLogs ( nodeName , applicationId , servicePackageName , codePackageName , servicePackageActivationId , tail , messageHandler ? ) { const url = 'Nodes/' + encodeURIComponent ( nodeName ) + '/$/GetApplications/' + encodeURIComponent ( applicationId ) + '/$/GetCodePackages' + '/$/ContainerLogs' ; const formedUrl = this . getApiUrl ( url ) + '&ServiceManifestName=' + encodeURIComponent ( servicePackageName ) + '&CodePackageName=' + encodeURIComponent ( codePackageName ) + '&ServicePackageActivationId=' + encodeURIComponent ( servicePackageActivationId ) + '&Tail=' + encodeURIComponent ( tail ) ; return this . get ( formedUrl , 'Get deployed container logs' , messageHandler ) ; } public restartCodePackage ( nodeName , applicationId , serviceManifestName , codePackageName , codePackageInstanceId , servicePackageActivationId ? , messageHandler ? ) { const url = 'Nodes/' + encodeURIComponent ( nodeName ) + '/$/GetApplications/' + encodeURIComponent ( applicationId ) + '/$/GetCodePackages/$/Restart' ; const body = { ServiceManifestName : serviceManifestName , CodePackageName : codePackageName , CodePackageInstanceId : codePackageInstanceId } ; if ( servicePackageActivationId ) { body . ServicePackageActivationId = servicePackageActivationId ; } return this . post ( this . getApiUrl ( url ) , 'Code package restart' , body , messageHandler ) ; } public getDeployedReplica ( nodeName , applicationId , servicePackageName , partitionId , messageHandler ? ) { const url = 'Nodes/' + encodeURIComponent ( nodeName ) + '/$/GetApplications/' + encodeURIComponent ( applicationId ) + '/$/GetReplicas' ; const formedUrl = this . getApiUrl ( url ) + '&PartitionId=' + encodeURIComponent ( partitionId ) + '&ServiceManifestName=' + encodeURIComponent ( servicePackageName ) ; return this . get ( formedUrl , 'Get deployed replica' , messageHandler ) ; } public getDeployedReplicaDetail ( nodeName , partitionId , replicaId , messageHandler ? ) { const url = 'Nodes/' + encodeURIComponent ( nodeName ) + '/$/GetPartitions/' + encodeURIComponent ( partitionId ) + '/$/GetReplicas/' + encodeURIComponent ( replicaId ) + '/$/GetDetail' ; return this . get ( this . getApiUrl ( url , RestClientService . apiVersion60 ) , 'Get deployed replica detail' , messageHandler ) ; } public getApplicationTypes ( appTypeName ? , messageHandler ? ) { if ( appTypeName ) { return this . get ( this . getApiUrl ( 'ApplicationTypes/' + encodeURIComponent ( appTypeName ) ) , 'Get application type' ) ; } return this . get ( this . getApiUrl ( 'ApplicationTypes/' ) , 'Get application types' , messageHandler ) ; } public getApplicationManifestForApplicationType ( appTypeName , appTypeVersion , messageHandler ? ) { const url = 'ApplicationTypes/' + encodeURIComponent ( appTypeName ) + '/$/GetApplicationManifest?ApplicationTypeVersion=' + encodeURIComponent ( appTypeVersion ) ; return this . get ( this . getApiUrl ( url ) , 'Get application manifest for application type' ) ; } public provisionApplication ( name , appTypeName , appTypeVersion , messageHandler ? ) { const url = 'Applications/$/Create' ; const body = { Name : name , TypeName : appTypeName , TypeVersion : appTypeVersion } ; return this . post ( this . getApiUrl ( url ) , 'Application instance creation' , body , messageHandler ) ; } public activateNode ( nodeName , messageHandler ? ) { const url = 'Nodes/' + encodeURIComponent ( nodeName ) + '/$/Activate' ; return this . post ( this . getApiUrl ( url ) , 'Node Activation' , null , messageHandler ) ; } public deactivateNode ( nodeName , intent , messageHandler ? ) { const url = 'Nodes/' + encodeURIComponent ( nodeName ) + '/$/Deactivate' ; return this . post ( this . getApiUrl ( url ) , 'Node deactivation' , { DeactivationIntent : intent } , messageHandler ) ; } public removeNodeState ( nodeName , messageHandler ? ) { const url = 'Nodes/' + encodeURIComponent ( nodeName ) + '/$/RemoveNodeState' ; return this . post ( this . getApiUrl ( url ) , 'Node state removal' , null , messageHandler ) ; } public getApplications ( excludeParams = false , messageHandler ? ) { let url = 'Applications/' ; if ( excludeParams ) { url = url + `?ExcludeApplicationParameters=true` ; } return this . getFullCollection < IRawApplication > ( url , 'Get applications' , null , messageHandler ) ; } public getServices ( applicationId , messageHandler ? ) { const url = 'Applications/' + encodeURIComponent ( applicationId ) + '/$/GetServices' ; return this . getFullCollection < IRawService > ( url , 'Get services' , null , messageHandler ) ; } public getService ( applicationId , serviceId , messageHandler ? ) { const url = 'Applications/' + encodeURIComponent ( applicationId ) + '/$/GetServices/' + encodeURIComponent ( serviceId ) ; return this . get ( this . getApiUrl ( url ) , 'Get service' , messageHandler ) ; } public createService ( applicationId , serviceDescription , messageHandler ? ) { const url = 'Applications/' + encodeURIComponent ( applicationId ) + '/$/GetServices/$/Create' ; return this . post ( this . getApiUrl ( url ) , 'Service creation' , serviceDescription , messageHandler ) ; } public createServiceFromTemplate ( applicationId , serviceDescription , messageHandler ? ) { const url = 'Applications/' + encodeURIComponent ( applicationId ) + '/$/GetServices/$/CreateFromTemplate' ; return this . post ( this . getApiUrl ( url ) , 'Service creation' , serviceDescription , messageHandler ) ; } public updateService ( applicationId , serviceId , updateServiceDescription , messageHandler ? ) { const url = `Applications/${ encodeURIComponent ( applicationId ) }/$/GetServices/${ encodeURIComponent ( serviceId ) }/$/Update` ; return this . post ( this . getApiUrl ( url ) , 'Service update' , updateServiceDescription , messageHandler ) ; } public enableApplicationBackup ( application , policyName , messageHandler ? ) { const url = 'Applications/' + encodeURIComponent ( application . id ) + '/$/EnableBackup' ; return this . post ( this . getApiUrl ( url , RestClientService . apiVersion64 ) , 'Enable Application Backup' , { BackupPolicyName : policyName } , messageHandler ) ; } public disableApplicationBackup ( application , cleanBackup , messageHandler ? ) { const url = 'Applications/' + encodeURIComponent ( application . id ) + '/$/DisableBackup' ; return this . post ( this . getApiUrl ( url , RestClientService . apiVersion64 ) , 'Disable Application Backup' , { CleanBackup : cleanBackup } , messageHandler ) ; } public enableServiceBackup ( service , backupPolicyName , messageHandler ? ) { const url = 'Services/' + encodeURIComponent ( service . id ) + '/$/EnableBackup' ; return this . post ( this . getApiUrl ( url , RestClientService . apiVersion64 ) , 'Enable Service Backup' , { BackupPolicyName : backupPolicyName } , messageHandler ) ; } public disableServiceBackup ( service , cleanBackup , messageHandler ? ) { const url = 'Services/' + encodeURIComponent ( service . id ) + '/$/DisableBackup' ; return this . post ( this . getApiUrl ( url , RestClientService . apiVersion64 ) , 'Disable Service Backup' , { CleanBackup : cleanBackup } , messageHandler ) ; } public enablePartitionBackup ( partition , backupPolicyName , messageHandler ? ) { const url = 'Partitions/' + encodeURIComponent ( partition . id ) + '/$/EnableBackup' ; return this . post ( this . getApiUrl ( url , RestClientService . apiVersion64 ) , 'Enable Service Backup' , { BackupPolicyName : backupPolicyName } , messageHandler ) ; } public disablePartitionBackup ( partition , cleanBackup , messageHandler ? ) { const url = 'Partitions/' + encodeURIComponent ( partition . id ) + '/$/DisableBackup' ; return this . post ( this . getApiUrl ( url , RestClientService . apiVersion64 ) , 'Disable Service Backup' , { CleanBackup : cleanBackup } , messageHandler ) ; } public suspendApplicationBackup ( applicationId , messageHandler ? ) { const url = 'Applications/' + encodeURIComponent ( applicationId ) + '/$/SuspendBackup' ; return this . post ( this . getApiUrl ( url , RestClientService . apiVersion64 ) , 'Suspend Application Backup' , null , messageHandler ) ; } public resumeApplicationBackup ( applicationId , messageHandler ? ) { const url = 'Applications/' + encodeURIComponent ( applicationId ) + '/$/ResumeBackup' ; return this . post ( this . getApiUrl ( url , RestClientService . apiVersion64 ) , 'Resume Application Backup' , null , messageHandler ) ; } public suspendServiceBackup ( serviceId , messageHandler ? ) { const url = 'Services/' + encodeURIComponent ( serviceId ) + '/$/SuspendBackup' ; return this . post ( this . getApiUrl ( url , RestClientService . apiVersion64 ) , 'Suspend Service Backup' , null , messageHandler ) ; } public resumeServiceBackup ( serviceId , messageHandler ? ) { const url = 'Services/' + encodeURIComponent ( serviceId ) + '/$/ResumeBackup' ; return this . post ( this . getApiUrl ( url , RestClientService . apiVersion64 ) , 'Resume Service Backup' , null , messageHandler ) ; } public suspendPartitionBackup ( partitionId , messageHandler ? ) { const url = 'Partitions/' + encodeURIComponent ( partitionId ) + '/$/SuspendBackup' ; return this . post ( this . getApiUrl ( url , RestClientService . apiVersion64 ) , 'Suspend Partition Backup' , null , messageHandler ) ; } public resumePartitionBackup ( partitionId , messageHandler ? ) { const url = 'Partitions/' + encodeURIComponent ( partitionId ) + '/$/ResumeBackup' ; return this . post ( this . getApiUrl ( url , RestClientService . apiVersion64 ) , 'Resume Partition Backup' , null , messageHandler ) ; } public deleteBackupPolicy ( backupPolicyName , messageHandler ? ) { const url = 'BackupRestore/BackupPolicies/' + encodeURIComponent ( backupPolicyName ) + '/$/Delete' ; return this . post ( this . getApiUrl ( url , RestClientService . apiVersion64 ) , 'Backup Policy deletion' , null , messageHandler ) ; } public updateBackupPolicy ( backupPolicy , messageHandler ? ) { const url = 'BackupRestore/BackupPolicies/' + encodeURIComponent ( backupPolicy . Name ) + '/$/Update' ; return this . post ( this . getApiUrl ( url , RestClientService . apiVersion64 ) + '&validateConnection=true' , 'Backup Policy updation' , backupPolicy , messageHandler ) ; } public createBackupPolicy ( backupPolicy , messageHandler ? ) { const url = 'BackupRestore/BackupPolicies/$/Create' ; return this . post ( this . getApiUrl ( url , RestClientService . apiVersion64 ) + '&validateConnection=true' , 'Backup Policy creation' , backupPolicy , messageHandler ) ; } public triggerPartitionBackup ( partition , timeOut , storage , messageHandler ? ) { let url = 'Partitions/' + encodeURIComponent ( partition . id ) + '/$/Backup' ; if ( timeOut ) { url += '?BackupTimeout=' + timeOut . toString ( ) ; } return this . post ( this . getApiUrl ( url , RestClientService . apiVersion64 ) , 'Partition Backup trigger' , { BackupStorage : storage } , messageHandler ) ; } public restorePartitionBackup ( partitionId , storage , timeOut , backupId , backupLocation , messageHandler ? ) { let url = 'Partitions/' + encodeURIComponent ( partitionId ) + '/$/Restore' ; if ( timeOut ) { url += '?RestoreTimeout=' + timeOut . toString ( ) ; } return this . post ( this . getApiUrl ( url , RestClientService . apiVersion64 ) , 'Partition Backup restore' , { BackupId : backupId , BackupStorage : storage , BackupLocation : backupLocation } , messageHandler ) ; } public getBackupEnabledEntities ( backupPolicyName , messageHandler ? ) { const url = 'BackupRestore/BackupPolicies/' + encodeURIComponent ( backupPolicyName ) + '/$/GetBackupEnabledEntities' ; return this . getFullCollection < IRawBackupEntity > ( url , 'Get Backup Enabled Entities' , RestClientService . apiVersion64 , messageHandler ) ; } public getServiceDescription ( applicationId , serviceId , messageHandler ? ) { const url = 'Applications/' + encodeURIComponent ( applicationId ) + '/$/GetServices/' + encodeURIComponent ( serviceId ) + '/$/GetDescription' ; return this . get ( this . getApiUrl ( url ) , 'Get service description' , messageHandler ) ; } public getServiceHealth ( applicationId , serviceId , eventsHealthStateFilter = HealthStateFilterFlags . Default , partitionsHealthStateFilter = HealthStateFilterFlags . Default , messageHandler ? ) { const url = `Applications/${ encodeURIComponent ( applicationId ) }/$/GetServices/${ encodeURIComponent ( serviceId ) }` + `/$/GetHealth?EventsHealthStateFilter=${ eventsHealthStateFilter }&PartitionsHealthStateFilter=${ partitionsHealthStateFilter }` ; return this . get ( this . getApiUrl ( url ) , 'Get service health' , messageHandler ) ; } public deleteService ( applicationId , serviceId , messageHandler ? ) { const url = 'Applications/' + encodeURIComponent ( applicationId ) + '/$/GetServices/' + encodeURIComponent ( serviceId ) + '/$/Delete' ; return this . post ( this . getApiUrl ( url ) , 'Service deletion' , null , messageHandler ) ; } public unprovisionApplicationType ( applicationTypeName , applicationTypeVersion , messageHandler ? ) { const url = 'ApplicationTypes/' + encodeURIComponent ( applicationTypeName ) + '/$/Unprovision' ; return this . post ( this . getApiUrl ( url ) , 'Application type unprovision' , { ApplicationTypeVersion : applicationTypeVersion } , messageHandler ) ; } public getApplication ( applicationId , excludeParams = false , messageHandler ? ) { let url = 'Applications/' + encodeURIComponent ( applicationId ) + '/' ; if ( excludeParams ) { url = url + `?ExcludeApplicationParameters=true` ; } return this . get ( this . getApiUrl ( url ) , 'Get application' , messageHandler ) ; } public getApplicationHealth ( applicationId , eventsHealthStateFilter = HealthStateFilterFlags . Default , servicesHealthStateFilter = HealthStateFilterFlags . Default , deployedApplicationsHealthStateFilter = HealthStateFilterFlags . Default , messageHandler ? ) { const url = `Applications/${ encodeURIComponent ( applicationId ) }/$/GetHealth` + `?EventsHealthStateFilter=${ eventsHealthStateFilter }&DeployedApplicationsHealthStateFilter=${ deployedApplicationsHealthStateFilter }` + `&ServicesHealthStateFilter=${ servicesHealthStateFilter }` ; return this . get ( this . getApiUrl ( url ) , 'Get application health' , messageHandler ) ; } public getApplicationUpgradeProgress ( applicationId , messageHandler ? ) { const url = 'Applications/' + encodeURIComponent ( applicationId ) + '/$/GetUpgradeProgress' ; return this . get ( this . getApiUrl ( url ) , 'Get application upgrade progress' , messageHandler ) ; } public deleteApplication ( applicationId , messageHandler ? ) { const url = 'Applications/' + encodeURIComponent ( applicationId ) + '/$/Delete' ; return this . post ( this . getApiUrl ( url ) , 'Application deletion' , null , messageHandler ) ; } public createComposeDeployment ( composeDeploymentDescription , messageHandler ? ) { const url = 'ComposeDeployments/$/Create' ; return this . put ( this . getApiUrl ( url , RestClientService . apiVersion60 ) , 'Compose application creation' , composeDeploymentDescription , messageHandler ) ; } public deleteComposeApplication ( applicationId , messageHandler ? ) { const url = 'ComposeDeployments/' + encodeURIComponent ( applicationId ) + '/$/Delete' ; return this . post ( this . getApiUrl ( url , RestClientService . apiVersion40 ) , 'Compose application deletion' , null , messageHandler ) ; } public getPartitions ( applicationId , serviceId , messageHandler ? ) { const url = 'Applications/' + encodeURIComponent ( applicationId ) + '/$/GetServices/' + encodeURIComponent ( serviceId ) + '/$/GetPartitions' ; return this . getFullCollection < IRawPartition > ( url , 'Get partitions' , null , messageHandler ) ; } public getPartition ( applicationId , serviceId , partitionId , messageHandler ? ) { const url = 'Applications/' + encodeURIComponent ( applicationId ) + '/$/GetServices/' + encodeURIComponent ( serviceId ) + '/$/GetPartitions/' + encodeURIComponent ( partitionId ) ; return this . get ( this . getApiUrl ( url ) , 'Get partition' , messageHandler ) ; } public getPartitionById ( partitionId , messageHandler ? ) { const url = 'Partitions/' + encodeURIComponent ( partitionId ) ; return this . get ( this . getApiUrl ( url , RestClientService . apiVersion60 ) , 'Get partition by id' , messageHandler ) ; } public getServiceNameInfo ( partitionId , messageHandler ? ) { const url = `Partitions/${ partitionId }/$/GetServiceName` ; return this . get ( this . getApiUrl ( url ) , 'Get service' , messageHandler ) ; } public getApplicationNameInfo ( serviceId , messageHandler ? ) { const url = `Services/${ serviceId }/$/GetApplicationName` ; return this . get ( this . getApiUrl ( url ) , 'Get service' , messageHandler ) ; } public getPartitionHealth ( applicationId , serviceId , partitionId , eventsHealthStateFilter = HealthStateFilterFlags . Default , replicasHealthStateFilter = HealthStateFilterFlags . Default , messageHandler ? ) { const url = `Applications/${ encodeURIComponent ( applicationId ) }/$/GetServices/${ encodeURIComponent ( serviceId ) }/$/GetPartitions/${ encodeURIComponent ( partitionId ) }` + `/$/GetHealth?EventsHealthStateFilter=${ eventsHealthStateFilter }&ReplicasHealthStateFilter=${ replicasHealthStateFilter }` ; return this . get ( this . getApiUrl ( url ) , 'Get partition health' , messageHandler ) ; } public getPartitionLoadInformation ( applicationId , serviceId , partitionId , messageHandler ? ) { const url = 'Applications/' + encodeURIComponent ( applicationId ) + '/$/GetServices/' + encodeURIComponent ( serviceId ) + '/$/GetPartitions/' + encodeURIComponent ( partitionId ) + '/$/GetLoadInformation' ; return this . get ( this . getApiUrl ( url ) , 'Get partition load information' , messageHandler ) ; } public getReplicasOnPartition ( applicationId , serviceId , partitionId , messageHandler ? ) { const url = 'Applications/' + encodeURIComponent ( applicationId ) + '/$/GetServices/' + encodeURIComponent ( serviceId ) + '/$/GetPartitions/' + encodeURIComponent ( partitionId ) + '/$/GetReplicas' ; return this . getFullCollection < IRawReplicaOnPartition > ( url , 'Get replicas on partition' , null , messageHandler ) ; } public getReplicaOnPartition ( applicationId , serviceId , partitionId , replicaId , messageHandler ? ) { const url = 'Applications/' + encodeURIComponent ( applicationId ) + '/$/GetServices/' + encodeURIComponent ( serviceId ) + '/$/GetPartitions/' + encodeURIComponent ( partitionId ) + '/$/GetReplicas/' + encodeURIComponent ( replicaId ) ; return this . get ( this . getApiUrl ( url ) , 'Get replica on partition' , messageHandler ) ; } public getReplicaHealth ( applicationId , serviceId , partitionId , replicaId , eventsHealthStateFilter = HealthStateFilterFlags . Default , messageHandler ? ) { const url = `Applications/${ encodeURIComponent ( applicationId ) }/$/GetServices/${ encodeURIComponent ( serviceId ) }` + `/$/GetPartitions/${ encodeURIComponent ( partitionId ) }/$/GetReplicas/${ encodeURIComponent ( replicaId ) }` + `/$/GetHealth?EventsHealthStateFilter=${ eventsHealthStateFilter }` ; return this . get ( this . getApiUrl ( url ) , 'Get replica health' , messageHandler ) ; } public getReplicasOnNode ( nodeName , applicationId , messageHandler ? ) { const url = 'Nodes/' + encodeURIComponent ( nodeName ) + '/$/GetApplications/' + encodeURIComponent ( applicationId ) + '/$/GetReplicas' ; return this . get ( this . getApiUrl ( url ) , 'Get replicas on node' , messageHandler ) ; } public deleteReplica ( nodeName , partitionId , replicaId , force ? , messageHandler ? ) { let url = 'Nodes/' + encodeURIComponent ( nodeName ) + '/$/GetPartitions/' + encodeURIComponent ( partitionId ) + '/$/GetReplicas/' + encodeURIComponent ( replicaId ) + '/$/Delete' ; if ( force ) { url += '?ForceRemove=true' ; } return this . post ( this . getApiUrl ( url ) , 'Replica deletion' , null , messageHandler ) ; } public getImageStoreContent ( path ? , messageHandler ? ) { let url = path ? `ImageStore/${ path }` : 'ImageStore' ; url += '?timeout=300' ; return this . get ( this . getApiUrl ( url , RestClientService . apiVersion60 ) , 'Get Image Store content' , messageHandler ) ; } public deleteImageStoreContent ( path , messageHandler ? ) { return this . delete ( this . getApiUrl ( `ImageStore/${ path }` , RestClientService . apiVersion60 ) , 'Delete Image Store content' , messageHandler ) ; } public getImageStoreFolderSize ( path ? , messageHandler ? ) { let url = ( path ? `ImageStore/${ path }` : 'ImageStore' ) + '/$/FolderSize' ; url += '?timeout=300' ; return this . get ( this . getApiUrl ( url , RestClientService . apiVersion65 ) , 'Get Image Store Folder Size' , messageHandler ) ; } public getClusterEvents ( startTime , endTime , messageHandler ? ) { return this . getEvents ( ClusterEvent , 'EventsStore/Cluster/Events' , startTime , endTime , messageHandler , RestClientService . apiVersion80 ) ; } public getNodeEvents ( startTime , endTime , nodeName ? , messageHandler ? ) { const url = 'EventsStore/' + 'Nodes/' + ( nodeName ? ( encodeURIComponent ( nodeName ) + '/$/' ) : '' ) + 'Events' ; return this . getEvents ( NodeEvent , url , startTime , endTime , messageHandler ) ; } public getApplicationEvents ( startTime , endTime , applicationId ? , messageHandler ? ) { const url = 'EventsStore/' + 'Applications/' + ( applicationId ? ( encodeURIComponent ( applicationId ) + '/$/' ) : '' ) + 'Events' ; return this . getEvents ( ApplicationEvent , url , startTime , endTime , messageHandler ) ; } public getServiceEvents ( startTime , endTime , serviceId ? , messageHandler ? ) { const url = 'EventsStore/' + 'Services/' + ( serviceId ? ( encodeURIComponent ( serviceId ) + '/$/' ) : '' ) + 'Events' ; return this . getEvents ( ServiceEvent , url , startTime , endTime , messageHandler ) ; } public getPartitionEvents ( startTime , endTime , partitionId ? , messageHandler ? ) { const url = 'EventsStore/' + 'Partitions/' + ( partitionId ? ( encodeURIComponent ( partitionId ) + '/$/' ) : '' ) + 'Events' ; return this . getEvents ( PartitionEvent , url , startTime , endTime , messageHandler ) ; } public getReplicaEvents ( startTime , endTime , partitionId , replicaId ? , messageHandler ? ) { const url = 'EventsStore/' + 'Partitions/' + encodeURIComponent ( partitionId ) + '/$/' + 'Replicas/' + ( replicaId ? ( encodeURIComponent ( replicaId ) + '/$/' ) : '' ) + 'Events' ; return this . getEvents ( ReplicaEvent , url , startTime , endTime , messageHandler ) ; } public getCorrelatedEvents ( eventInstanceId , messageHandler ? ) { const url = 'EventsStore/' + 'CorrelatedEvents/' + encodeURIComponent ( eventInstanceId ) + '/$/' + 'Events' ; return this . getEvents ( FabricEvent , url , null , null , messageHandler ) ; } public getRepairTasks ( messageHandler ? ) { const url = `$/GetRepairTaskList` ; return this . get ( this . getApiUrl ( url , RestClientService . apiVersion60 ) , 'Get repair tasks' , messageHandler ) ; } public restartReplica ( nodeName , partitionId , replicaId , messageHandler ? ) { const url = `Nodes/${ nodeName }/$/GetPartitions/${ partitionId }/$/GetReplicas/${ replicaId }/$/Restart` ; return this . post ( this . getApiUrl ( url , RestClientService . apiVersion60 ) , 'Restart replica' , null , messageHandler ) ; } public getClusterVersion ( messageHandler ? ) { const url = `$/GetClusterVersion` ; return this . get ( this . getApiUrl ( url , RestClientService . apiVersion64 ) , 'Get cluster version' , messageHandler ) ; } private getEvents < T extends FabricEventBase > ( eventType , url , startTime ? , endTime ? , messageHandler ? , apiVersion ? ) { let apiUrl = url ; if ( startTime && endTime ) { apiUrl = apiUrl + '?starttimeutc=' + startTime . toISOString ( ) . substr ( 0 , 19 ) + 'Z' + '&endtimeutc=' + endTime . toISOString ( ) . substr ( 0 , 19 ) + 'Z' ; } if ( ! apiVersion ) { apiVersion = RestClientService . apiVersion72 ; } const fullUrl = this . getApiUrl ( apiUrl , apiVersion , null , true ) ; return this . get < IRawList < { } > > ( fullUrl , null , messageHandler ) . pipe ( map ( response => { return new EventsResponseAdapter ( eventType ) . getEvents ( response ) ; } ) ) ; } param path param apiVersion private getApiUrl ( path , apiVersion = RestClientService . defaultApiVersion , continuationToken ? , skipCacheToken ? ) { if ( ! environment . production ) { skipCacheToken = true ; } return StandaloneIntegration . clusterUrl + `/${ path }${ path . indexOf ( '?' ) === - 1 ? '?' : '&' }api-version=${ apiVersion ? apiVersion : RestClientService . defaultApiVersion }${ skipCacheToken === true ? '' : `&_cacheToken=${ this . cacheAllowanceToken }` }${ continuationToken ? `&ContinuationToken=${ continuationToken }` : '' }` ; } private getApiUrl2 ( path , apiVersion = RestClientService . defaultApiVersion , continuationToken ? , skipCacheToken ? , startDate ? , endDate ? , maxResults ? , latest ? ) { const appUrl = this . getApiUrl ( path , apiVersion , continuationToken , false ) ; return appUrl + `${ maxResults === undefined || maxResults === null ? '' : `&MaxResults=${ maxResults }` }${ ( startDate === undefined || startDate === null || endDate === undefined || endDate === null ) ? '' : `&StartDateTimeFilter=${ startDate . toISOString ( ) . substr ( 0 , 19 ) }Z&EndDateTimeFilter=${ endDate . toISOString ( ) . substr ( 0 , 19 ) }Z` }${ latest === true ? `&Latest=True` : '' }` ; } private getFullCollection < T > ( url , apiDesc , apiVersion ? , messageHandler ? , continuationToken ? ) { const appUrl = this . getApiUrl ( url , apiVersion , continuationToken , false ) ; return this . get < IRawCollection < T > > ( appUrl , apiDesc , messageHandler ) . pipe ( mergeMap ( response => { if ( response . ContinuationToken ) { return this . getFullCollection < T > ( url , apiDesc , apiVersion , messageHandler , response . ContinuationToken ) . pipe ( mergeMap ( items => { return of ( response . Items . concat ( items ) ) ; } ) ) ; } else { return of ( response . Items ) ; } } ) ) ; } private getFullCollection2 < T > ( url , apiDesc , apiVersion ? , messageHandler ? , continuationToken ? , startDate ? , endDate ? , maxResults ? , latest ? ) { const appUrl = this . getApiUrl2 ( url , apiVersion , continuationToken , false , startDate , endDate , maxResults , latest ) ; return this . get < IRawCollection < T > > ( appUrl , apiDesc , messageHandler ) . pipe ( mergeMap ( response => { if ( response . ContinuationToken ) { return this . getFullCollection < T > ( url , apiDesc , apiVersion , messageHandler , response . ContinuationToken ) . pipe ( map ( items => { return response . Items . concat ( items ) ; } ) ) ; } else { return of ( response . Items ) ; } } ) ) ; } private get < T > ( url , apiDesc , messageHandler ? ) { const result = this . httpClient . get < T > ( environment . baseUrl + url ) ; if ( ! messageHandler ) { messageHandler = ResponseMessageHandlers . getResponseMessageHandler ; } return this . handleResponse < T > ( apiDesc , result as any , messageHandler ) ; } private post < T > ( url , apiDesc , data ? , messageHandler ? ) { const result = this . httpClient . post < T > ( environment . baseUrl + url , data ) ; if ( ! messageHandler ) { messageHandler = ResponseMessageHandlers . postResponseMessageHandler ; } return this . handleResponse < T > ( apiDesc , result as any , messageHandler ) ; } private put < T > ( url , apiDesc , data ? , messageHandler ? ) { const result = this . httpClient . put < T > ( environment . baseUrl + url , data ) ; if ( ! messageHandler ) { messageHandler = ResponseMessageHandlers . putResponseMessageHandler ; } return this . handleResponse < T > ( apiDesc , result as any , messageHandler ) ; } private delete < T > ( url , apiDesc , messageHandler ? ) { const result = this . httpClient . delete < T > ( environment . baseUrl + url ) ; if ( ! messageHandler ) { messageHandler = ResponseMessageHandlers . deleteResponseMessageHandler ; } return this . handleResponse < T > ( apiDesc , result as any , messageHandler ) ; } private handleResponse < T > ( apiDesc , resultPromise , messageHandler ? ) { const data = { startTime : new Date ( ) . toISOString ( ) , apiDesc , errorMessage : '' , duration : 0 , data : null , statusCode : 200 } ; return resultPromise . pipe ( catchError ( ( err ) => { const header = `${ err . status . toString ( ) } : ${ apiDesc }` ; const message = messageHandler . getErrorMessage ( apiDesc , err ) ; let displayMessage = '' ; if ( message ) { displayMessage = message ; } else if ( err . error instanceof Error ) { displayMessage = err . error . message ; } else { displayMessage = err . message ; } this . message . showMessage ( displayMessage , MessageSeverity . Err , header ) ; data . errorMessage = displayMessage ; data . statusCode = err . status ; return throwError ( err ) ; } ) , finalize ( ( ) => { data . duration = new Date ( ) . getTime ( ) - new Date ( data . startTime ) . getTime ( ) ; this . networkDebugger . addRequest ( data ) ; } ) ) ; } }