module Sfx { /**
     * Service fabric REST api client, this should be only be used in DataService.
     */ export class RestClient { private static defaultApiVersion : string = "3.0" ; private static apiVersion40 : string = "4.0" ; private static apiVersion60 : string = "6.0" ; private static apiVersion62Preview : string = "6.2-preview" ; private static apiVersion64 : string = "6.4" ; private static apiVersion65 : string = "6.5" ; private static apiVersion72 : string = "7.2" ; private cacheAllowanceToken : number = Date . now ( ) . valueOf ( ) ; private requestCount : number = 0 ; private requestStarted : { ( param ) : void ; } [ ] = [ ] ; private requestEnded : { ( param ) : void ; } [ ] = [ ] ; private allRequestsComplete : { ( ) : void ; } [ ] = [ ] ; constructor ( private httpClient , private message ) { this . registerRequestEndedCallback ( requestCount => { if ( requestCount === 0 ) { $ . each ( this . allRequestsComplete , ( _ , cb ) => cb ( ) ) ; this . allRequestsComplete = [ ] ; } } ) ; } public invalidateBrowserRestResponseCache ( ) { this . cacheAllowanceToken = Date . now ( ) . valueOf ( ) ; } public registerRequestStartedCallback ( callback ) { this . requestStarted . push ( callback ) ; return this ; } public registerRequestEndedCallback ( callback ) { this . requestEnded . push ( callback ) ; return this ; } public registerAllRequestsCompleteCallback ( callback ) { if ( this . requestCount === 0 ) { callback ( ) ; } else { this . allRequestsComplete . push ( callback ) ; } } public getClusterHealth ( eventsHealthStateFilter = HealthStateFilterFlags . Default , nodesHealthStateFilter = HealthStateFilterFlags . Default , applicationsHealthStateFilter = HealthStateFilterFlags . Default , messageHandler ? ) { let 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" ) , "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 createNetwork ( networkName , networkAddressPrefix , messageHandler ? ) { let url = "Resources/Networks/" + encodeURIComponent ( networkName ) ; let body = { "name" : networkName , "properties" : { "kind" : "Local" , "networkAddressPrefix" : networkAddressPrefix } } ; return this . put ( this . getApiUrl ( url , RestClient . apiVersion64 ) , "Creating isolated network \"" + networkName + "\" succeeded" , body , messageHandler ) ; } public getNetwork ( networkName , messageHandler ? ) { let url = "Resources/Networks/" + encodeURIComponent ( networkName ) + "/" ; return this . get ( this . getApiUrl ( url , RestClient . apiVersion64 ) , "Get network" , messageHandler ) ; } public getNetworks ( messageHandler ? ) { return this . getFullCollection < IRawNetwork > ( "Resources/Networks/" , "Get networks" , RestClient . apiVersion64 ) ; } public deleteNetwork ( networkName , messageHandler ? ) { let url = "Resources/Networks/" + encodeURIComponent ( networkName ) ; return this . delete ( this . getApiUrl ( url , RestClient . apiVersion64 ) , "Network \"" + networkName + "\" deleted" , messageHandler ) ; } public getNetworksOnApp ( appId , messageHandler ? ) { let url = "Applications/" + encodeURIComponent ( appId ) + "/$/GetNetworks" ; return this . getFullCollection < IRawNetworkOnApp > ( url , "Get networks attached to a application" , RestClient . apiVersion60 ) ; } public getNetworksOnNode ( nodeName , messageHandler ? ) { let url = "Nodes/" + encodeURIComponent ( nodeName ) + "/$/GetNetworks" ; return this . getFullCollection < IRawNetworkOnNode > ( url , "Get networks deployed on a node" , RestClient . apiVersion60 ) ; } public getAppsOnNetwork ( networkName , messageHandler ? ) { let url = "Resources/Networks/" + encodeURIComponent ( networkName ) + "/ApplicationRefs" ; return this . getFullCollection < IRawAppOnNetwork > ( url , "Get applications using current network" , RestClient . apiVersion64 ) ; } public getNodesOnNetwork ( networkName , messageHandler ? ) { let url = "Resources/Networks/" + encodeURIComponent ( networkName ) + "/DeployedNodes" ; return this . getFullCollection < IRawNodeOnNetwork > ( url , "Get nodes, current network is deployed on" , RestClient . apiVersion64 ) ; } public getDeployedContainersOnNetwork ( networkName , nodeName , messageHandler ? ) { let url = "Nodes/" + encodeURIComponent ( nodeName ) + "/$/GetNetworks/" + encodeURIComponent ( networkName ) + "/$/GetCodePackages" ; return this . getFullCollection < IRawDeployedContainerOnNetwork > ( url , "Get containers on network" , RestClient . apiVersion60 ) ; } public getNodes ( messageHandler ? ) { return this . getFullCollection < IRawNode > ( "Nodes/" , "Get nodes" ) ; } public getNode ( nodeName , messageHandler ? ) { let url = "Nodes/" + encodeURIComponent ( nodeName ) + "/" ; return this . get ( this . getApiUrl ( url ) , "Get node" , messageHandler ) ; } public getBackupPolicies ( messageHandler ? ) { return this . getFullCollection < IRawBackupPolicy > ( "BackupRestore/BackupPolicies/" , "Get backup Policies" , RestClient . apiVersion64 ) ; } public getApplicationBackupConfigurationInfoCollection ( applicationId , messageHandler ? ) { return this . getFullCollection < IRawApplicationBackupConfigurationInfo > ( "Applications/" + encodeURIComponent ( applicationId ) + "/$/GetBackupConfigurationInfo" , "Gets the application backup configuration information" , RestClient . apiVersion64 , messageHandler ) ; } public getServiceBackupConfigurationInfoCollection ( serviceId , messageHandler ? ) { return this . getFullCollection < IRawServiceBackupConfigurationInfo > ( "Services/" + encodeURIComponent ( serviceId ) + "/$/GetBackupConfigurationInfo" , "Gets the application backup configuration information" , RestClient . apiVersion64 , messageHandler ) ; } public getPartitionBackupProgress ( partitionId , messageHandler ? ) { return this . get ( this . getApiUrl ( "Partitions/" + encodeURIComponent ( partitionId ) + "/$/GetBackupProgress" , RestClient . apiVersion64 ) , "Gets the partition backup progress" , messageHandler ) ; } public getPartitionRestoreProgress ( partitionId , messageHandler ? ) { return this . get ( this . getApiUrl ( "Partitions/" + encodeURIComponent ( partitionId ) + "/$/GetRestoreProgress" , RestClient . apiVersion64 ) , "Gets the partition restore progress" , messageHandler ) ; } public getPartitionBackupConfigurationInfo ( partitionId , messageHandler ? ) { return this . get ( this . getApiUrl ( "Partitions/" + encodeURIComponent ( partitionId ) + "/$/GetBackupConfigurationInfo" , RestClient . 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" , RestClient . 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" , RestClient . apiVersion64 , messageHandler , undefined , startDate , endDate , maxResults ) ; } public getBackupPolicy ( backupName , messageHandler ? ) { let url = "BackupRestore/BackupPolicies/" + encodeURIComponent ( backupName ) + "/" ; return this . get ( this . getApiUrl ( url , RestClient . apiVersion64 ) , "Get backup policy" , messageHandler ) ; } public getNodeHealth ( nodeName , eventsHealthStateFilter = HealthStateFilterFlags . Default , messageHandler ? ) { let url = `Nodes/${ encodeURIComponent ( nodeName ) }/$/GetHealth?EventsHealthStateFilter=${ eventsHealthStateFilter }` ; return this . get ( this . getApiUrl ( url ) , "Get node health" , messageHandler ) ; } public getNodeLoadInformation ( nodeName , messageHandler ? ) { let url = "Nodes/" + encodeURIComponent ( nodeName ) + "/$/GetLoadInformation" ; return this . get ( this . getApiUrl ( url ) , "Get node load information" , messageHandler ) ; } public restartNode ( nodeName , nodeInstanceId , messageHandler ? ) { let url = "Nodes/" + encodeURIComponent ( nodeName ) + "/$/Restart" ; let body = { "NodeInstanceId" : nodeInstanceId } ; return this . post ( this . getApiUrl ( url ) , "Node restart" , body , messageHandler ) ; } public getDeployedApplications ( nodeName , messageHandler ? ) { let url = "Nodes/" + encodeURIComponent ( nodeName ) + "/$/GetApplications" ; return this . get ( this . getApiUrl ( url ) , "Get applications" , messageHandler ) ; } public getDeployedApplication ( nodeName , applicationId , messageHandler ? ) { let 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 ? ) { let 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 ? ) { let 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 ? ) { let 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 ? ) { let 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 ? ) { let url = "ApplicationTypes/" + encodeURIComponent ( appTypeName ) + "/$/GetServiceManifest" ; let 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 ? ) { let url = "ApplicationTypes/" + encodeURIComponent ( appTypeName ) + "/$/GetServiceTypes?ApplicationTypeVersion=" + encodeURIComponent ( appTypeVersion ) ; let formedUrl = this . getApiUrl ( url ) + "&ApplicationTypeVersion=" + encodeURIComponent ( appTypeVersion ) ; return this . get ( formedUrl , "Get service types for application type" , messageHandler ) ; } public getDeployedReplicas ( nodeName , applicationId , servicePackageName , messageHandler ? ) { let url = "Nodes/" + encodeURIComponent ( nodeName ) + "/$/GetApplications/" + encodeURIComponent ( applicationId ) + "/$/GetReplicas" ; let formedUrl = this . getApiUrl ( url ) + "&ServiceManifestName=" + encodeURIComponent ( servicePackageName ) ; return this . get ( formedUrl , "Get replicas on service" , messageHandler ) ; } public getDeployedCodePackages ( nodeName , applicationId , servicePackageName , messageHandler ? ) { let url = "Nodes/" + encodeURIComponent ( nodeName ) + "/$/GetApplications/" + encodeURIComponent ( applicationId ) + "/$/GetCodePackages" ; let formedUrl = this . getApiUrl ( url ) + "&ServiceManifestName=" + encodeURIComponent ( servicePackageName ) ; return this . get ( formedUrl , "Get deployed code packages" , messageHandler ) ; } public getDeployedCodePackage ( nodeName , applicationId , servicePackageName , codePackageName , messageHandler ? ) { let url = "Nodes/" + encodeURIComponent ( nodeName ) + "/$/GetApplications/" + encodeURIComponent ( applicationId ) + "/$/GetCodePackages" ; let 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 ? ) { let url = "Nodes/" + encodeURIComponent ( nodeName ) + "/$/GetApplications/" + encodeURIComponent ( applicationId ) + "/$/GetCodePackages" + "/$/ContainerLogs" ; let 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 ? ) { let url = "Nodes/" + encodeURIComponent ( nodeName ) + "/$/GetApplications/" + encodeURIComponent ( applicationId ) + "/$/GetCodePackages/$/Restart" ; let 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 ? ) { let url = "Nodes/" + encodeURIComponent ( nodeName ) + "/$/GetApplications/" + encodeURIComponent ( applicationId ) + "/$/GetReplicas" ; let formedUrl = this . getApiUrl ( url ) + "&PartitionId=" + encodeURIComponent ( partitionId ) + "&ServiceManifestName=" + encodeURIComponent ( servicePackageName ) ; return this . get ( formedUrl , "Get deployed replica" , messageHandler ) ; } public getDeployedReplicaDetail ( nodeName , partitionId , replicaId , messageHandler ? ) { let url = "Nodes/" + encodeURIComponent ( nodeName ) + "/$/GetPartitions/" + encodeURIComponent ( partitionId ) + "/$/GetReplicas/" + encodeURIComponent ( replicaId ) + "/$/GetDetail" ; return this . get ( this . getApiUrl ( url ) , "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 ? ) { let 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 ? ) { let url = "Applications/$/Create" ; let body = { "Name" : name , "TypeName" : appTypeName , "TypeVersion" : appTypeVersion } ; return this . post ( this . getApiUrl ( url ) , "Application instance creation" , body , messageHandler ) ; } public activateNode ( nodeName , messageHandler ? ) { let url = "Nodes/" + encodeURIComponent ( nodeName ) + "/$/Activate" ; return this . post ( this . getApiUrl ( url ) , "Node Activation" , null , messageHandler ) ; } public deactivateNode ( nodeName , intent , messageHandler ? ) { let url = "Nodes/" + encodeURIComponent ( nodeName ) + "/$/Deactivate" ; return this . post ( this . getApiUrl ( url ) , "Node deactivation" , { "DeactivationIntent" : intent } , messageHandler ) ; } public removeNodeState ( nodeName , messageHandler ? ) { let url = "Nodes/" + encodeURIComponent ( nodeName ) + "/$/RemoveNodeState" ; return this . post ( this . getApiUrl ( url ) , "Node state removal" , null , messageHandler ) ; } public getApplications ( messageHandler ? ) { return this . getFullCollection < IRawApplication > ( "Applications/" , "Get applications" , null , messageHandler ) ; } public getServices ( applicationId , messageHandler ? ) { let url = "Applications/" + encodeURIComponent ( applicationId ) + "/$/GetServices" ; return this . getFullCollection < IRawService > ( url , "Get services" , null , messageHandler ) ; } public getService ( applicationId , serviceId , messageHandler ? ) { let url = "Applications/" + encodeURIComponent ( applicationId ) + "/$/GetServices/" + encodeURIComponent ( serviceId ) ; return this . get ( this . getApiUrl ( url ) , "Get service" , messageHandler ) ; } public createService ( applicationId , serviceDescription , messageHandler ? ) { let url = "Applications/" + encodeURIComponent ( applicationId ) + "/$/GetServices/$/Create" ; return this . post ( this . getApiUrl ( url ) , "Service creation" , serviceDescription , messageHandler ) ; } public createServiceFromTemplate ( applicationId , serviceDescription , messageHandler ? ) { let url = "Applications/" + encodeURIComponent ( applicationId ) + "/$/GetServices/$/CreateFromTemplate" ; return this . post ( this . getApiUrl ( url ) , "Service creation" , serviceDescription , messageHandler ) ; } public updateService ( applicationId , serviceId , updateServiceDescription , messageHandler ? ) { let url = `Applications/${ encodeURIComponent ( applicationId ) }/$/GetServices/${ encodeURIComponent ( serviceId ) }/$/Update` ; return this . post ( this . getApiUrl ( url ) , "Service update" , updateServiceDescription , messageHandler ) ; } public enableApplicationBackup ( application , messageHandler ? ) { let url = "Applications/" + encodeURIComponent ( application . id ) + "/$/EnableBackup" ; return this . post ( this . getApiUrl ( url , RestClient . apiVersion64 ) , "Enable Application Backup" , { BackupPolicyName : application . backupPolicyName } , messageHandler ) ; } public disableApplicationBackup ( application , messageHandler ? ) { let url = "Applications/" + encodeURIComponent ( application . id ) + "/$/DisableBackup" ; return this . post ( this . getApiUrl ( url , RestClient . apiVersion64 ) , "Disable Application Backup" , { CleanBackup : application . cleanBackup } , messageHandler ) ; } public enableServiceBackup ( service , messageHandler ? ) { let url = "Services/" + encodeURIComponent ( service . id ) + "/$/EnableBackup" ; return this . post ( this . getApiUrl ( url , RestClient . apiVersion64 ) , "Enable Service Backup" , { BackupPolicyName : service . backupPolicyName } , messageHandler ) ; } public disableServiceBackup ( service , messageHandler ? ) { let url = "Services/" + encodeURIComponent ( service . id ) + "/$/DisableBackup" ; return this . post ( this . getApiUrl ( url , RestClient . apiVersion64 ) , "Disable Service Backup" , { CleanBackup : service . cleanBackup } , messageHandler ) ; } public enablePartitionBackup ( partition , messageHandler ? ) { let url = "Partitions/" + encodeURIComponent ( partition . id ) + "/$/EnableBackup" ; return this . post ( this . getApiUrl ( url , RestClient . apiVersion64 ) , "Enable Service Backup" , { BackupPolicyName : partition . partitionBackupInfo . backupPolicyName } , messageHandler ) ; } public disablePartitionBackup ( partition , messageHandler ? ) { let url = "Partitions/" + encodeURIComponent ( partition . id ) + "/$/DisableBackup" ; return this . post ( this . getApiUrl ( url , RestClient . apiVersion64 ) , "Disable Service Backup" , { CleanBackup : partition . partitionBackupInfo . cleanBackup } , messageHandler ) ; } public suspendApplicationBackup ( applicationId , messageHandler ? ) { let url = "Applications/" + encodeURIComponent ( applicationId ) + "/$/SuspendBackup" ; return this . post ( this . getApiUrl ( url , RestClient . apiVersion64 ) , "Suspend Application Backup" , null , messageHandler ) ; } public resumeApplicationBackup ( applicationId , messageHandler ? ) { let url = "Applications/" + encodeURIComponent ( applicationId ) + "/$/ResumeBackup" ; return this . post ( this . getApiUrl ( url , RestClient . apiVersion64 ) , "Resume Application Backup" , null , messageHandler ) ; } public suspendServiceBackup ( serviceId , messageHandler ? ) { let url = "Services/" + encodeURIComponent ( serviceId ) + "/$/SuspendBackup" ; return this . post ( this . getApiUrl ( url , RestClient . apiVersion64 ) , "Suspend Service Backup" , null , messageHandler ) ; } public resumeServiceBackup ( serviceId , messageHandler ? ) { let url = "Services/" + encodeURIComponent ( serviceId ) + "/$/ResumeBackup" ; return this . post ( this . getApiUrl ( url , RestClient . apiVersion64 ) , "Resume Service Backup" , null , messageHandler ) ; } public suspendPartitionBackup ( partitionId , messageHandler ? ) { let url = "Partitions/" + encodeURIComponent ( partitionId ) + "/$/SuspendBackup" ; return this . post ( this . getApiUrl ( url , RestClient . apiVersion64 ) , "Suspend Partition Backup" , null , messageHandler ) ; } public resumePartitionBackup ( partitionId , messageHandler ? ) { let url = "Partitions/" + encodeURIComponent ( partitionId ) + "/$/ResumeBackup" ; return this . post ( this . getApiUrl ( url , RestClient . apiVersion64 ) , "Resume Partition Backup" , null , messageHandler ) ; } public deleteBackupPolicy ( backupPolicyName , messageHandler ? ) { let url = "BackupRestore/BackupPolicies/" + encodeURIComponent ( backupPolicyName ) + "/$/Delete" ; return this . post ( this . getApiUrl ( url , RestClient . apiVersion64 ) , "Backup Policy deletion" , null , messageHandler ) ; } public updateBackupPolicy ( backupPolicy , messageHandler ? ) { let url = "BackupRestore/BackupPolicies/" + encodeURIComponent ( backupPolicy . Name ) + "/$/Update" ; return this . post ( this . getApiUrl ( url , RestClient . apiVersion64 ) , "Backup Policy updation" , backupPolicy , messageHandler ) ; } public createBackupPolicy ( backupPolicy , messageHandler ? ) { let url = "BackupRestore/BackupPolicies/$/Create" ; return this . post ( this . getApiUrl ( url , RestClient . apiVersion64 ) , "Backup Policy creation" , backupPolicy , messageHandler ) ; } public triggerPartitionBackup ( partition , messageHandler ? ) { let url = "Partitions/" + encodeURIComponent ( partition . id ) + "/$/Backup" ; if ( partition . partitionBackupInfo . BackupTimeout ) { url += "?BackupTimeout=" + partition . partitionBackupInfo . BackupTimeout . toString ( ) ; } return this . post ( this . getApiUrl ( url , RestClient . apiVersion64 ) , "Partition Backup trigger" , { "BackupStorage" : partition . partitionBackupInfo . storage } , messageHandler ) ; } public restorePartitionBackup ( partition , messageHandler ? ) { let url = "Partitions/" + encodeURIComponent ( partition . id ) + "/$/Restore" ; if ( partition . partitionBackupInfo . RestoreTimeout ) { url += "?RestoreTimeout=" + partition . partitionBackupInfo . RestoreTimeout . toString ( ) ; } return this . post ( this . getApiUrl ( url , RestClient . apiVersion64 ) , "Partition Backup restore" , { "BackupId" : partition . partitionBackupInfo . backupId , "BackupStorage" : partition . partitionBackupInfo . storage , "BackupLocation" : partition . partitionBackupInfo . backupLocation } , messageHandler ) ; } public getServiceDescription ( applicationId , serviceId , messageHandler ? ) { let 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 ? ) { let 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 ? ) { let url = "Applications/" + encodeURIComponent ( applicationId ) + "/$/GetServices/" + encodeURIComponent ( serviceId ) + "/$/Delete" ; return this . post ( this . getApiUrl ( url ) , "Service deletion" , null , messageHandler ) ; } public unprovisionApplicationType ( applicationTypeName , applicationTypeVersion , messageHandler ? ) { let url = "ApplicationTypes/" + encodeURIComponent ( applicationTypeName ) + "/$/Unprovision" ; return this . post ( this . getApiUrl ( url ) , "Application type unprovision" , { "ApplicationTypeVersion" : applicationTypeVersion } , messageHandler ) ; } public getApplication ( applicationId , messageHandler ? ) { let url = "Applications/" + encodeURIComponent ( applicationId ) + "/" ; return this . get ( this . getApiUrl ( url ) , "Get application" , messageHandler ) ; } public getApplicationHealth ( applicationId , eventsHealthStateFilter = HealthStateFilterFlags . Default , servicesHealthStateFilter = HealthStateFilterFlags . Default , deployedApplicationsHealthStateFilter = HealthStateFilterFlags . Default , messageHandler ? ) { let 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 ? ) { let url = "Applications/" + encodeURIComponent ( applicationId ) + "/$/GetUpgradeProgress" ; return this . get ( this . getApiUrl ( url ) , "Get application upgrade progress" , messageHandler ) ; } public deleteApplication ( applicationId , messageHandler ? ) { let url = "Applications/" + encodeURIComponent ( applicationId ) + "/$/Delete" ; return this . post ( this . getApiUrl ( url ) , "Application deletion" , null , messageHandler ) ; } public createComposeDeployment ( composeDeploymentDescription , messageHandler ? ) { let url = "ComposeDeployments/$/Create" ; return this . put ( this . getApiUrl ( url , RestClient . apiVersion60 ) , "Compose application creation" , composeDeploymentDescription , messageHandler ) ; } public deleteComposeApplication ( applicationId , messageHandler ? ) { let url = "ComposeDeployments/" + encodeURIComponent ( applicationId ) + "/$/Delete" ; return this . post ( this . getApiUrl ( url , RestClient . apiVersion40 ) , "Compose application deletion" , null , messageHandler ) ; } public getPartitions ( applicationId , serviceId , messageHandler ? ) { let url = "Applications/" + encodeURIComponent ( applicationId ) + "/$/GetServices/" + encodeURIComponent ( serviceId ) + "/$/GetPartitions" ; return this . getFullCollection < IRawPartition > ( url , "Get partitions" , null , messageHandler ) ; } public getPartition ( applicationId , serviceId , partitionId , messageHandler ? ) { let url = "Applications/" + encodeURIComponent ( applicationId ) + "/$/GetServices/" + encodeURIComponent ( serviceId ) + "/$/GetPartitions/" + encodeURIComponent ( partitionId ) ; return this . get ( this . getApiUrl ( url ) , "Get partition" , messageHandler ) ; } public getPartitionById ( partitionId , messageHandler ? ) { let url = "Partitions/" + encodeURIComponent ( partitionId ) ; return this . get ( this . getApiUrl ( url , RestClient . apiVersion60 ) , "Get partition by id" , messageHandler ) ; } public getPartitionHealth ( applicationId , serviceId , partitionId , eventsHealthStateFilter = HealthStateFilterFlags . Default , replicasHealthStateFilter = HealthStateFilterFlags . Default , messageHandler ? ) { let 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 ? ) { let 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 ? ) { let 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 ? ) { let 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 ? ) { let 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 ? ) { let 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 , RestClient . apiVersion60 ) , "Get Image Store content" , messageHandler ) ; } public deleteImageStoreContent ( path , messageHandler ? ) { return this . delete ( this . getApiUrl ( `ImageStore/${ path }` , RestClient . 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 , RestClient . apiVersion65 ) , "Get Image Store Folder Size" , messageHandler ) ; } public getClusterEvents ( startTime , endTime , messageHandler ? ) { return this . getEvents ( ClusterEvent , "EventsStore/Cluster/Events" , startTime , endTime , messageHandler ) ; } public getNodeEvents ( startTime , endTime , nodeName ? , messageHandler ? ) { let url = "EventsStore/" + "Nodes/" + ( nodeName ? ( encodeURIComponent ( nodeName ) + "/$/" ) : "" ) + "Events" ; return this . getEvents ( NodeEvent , url , startTime , endTime , messageHandler ) ; } public getApplicationEvents ( startTime , endTime , applicationId ? , messageHandler ? ) { let url = "EventsStore/" + "Applications/" + ( applicationId ? ( encodeURIComponent ( applicationId ) + "/$/" ) : "" ) + "Events" ; return this . getEvents ( ApplicationEvent , url , startTime , endTime , messageHandler ) ; } public getServiceEvents ( startTime , endTime , serviceId ? , messageHandler ? ) { let url = "EventsStore/" + "Services/" + ( serviceId ? ( encodeURIComponent ( serviceId ) + "/$/" ) : "" ) + "Events" ; return this . getEvents ( ServiceEvent , url , startTime , endTime , messageHandler ) ; } public getPartitionEvents ( startTime , endTime , partitionId ? , messageHandler ? ) { let url = "EventsStore/" + "Partitions/" + ( partitionId ? ( encodeURIComponent ( partitionId ) + "/$/" ) : "" ) + "Events" ; return this . getEvents ( PartitionEvent , url , startTime , endTime , messageHandler ) ; } public getReplicaEvents ( startTime , endTime , partitionId , replicaId ? , messageHandler ? ) { let url = "EventsStore/" + "Partitions/" + encodeURIComponent ( partitionId ) + "/$/" + "Replicas/" + ( replicaId ? ( encodeURIComponent ( replicaId ) + "/$/" ) : "" ) + "Events" ; return this . getEvents ( ReplicaEvent , url , startTime , endTime , messageHandler ) ; } public getCorrelatedEvents ( eventInstanceId , messageHandler ? ) { let url = "EventsStore/" + "CorrelatedEvents/" + encodeURIComponent ( eventInstanceId ) + "/$/" + "Events" ; return this . getEvents ( FabricEvent , url , null , null , messageHandler ) ; } public restartReplica ( nodeName , partitionId , replicaId , messageHandler ? ) { let url = `Nodes/${ nodeName }/$/GetPartitions/${ partitionId }/$/GetReplicas/${ replicaId }/$/Restart` ; return this . post ( this . getApiUrl ( url , RestClient . apiVersion60 ) , "Restart replica" , null , messageHandler ) ; } public getClusterVersion ( messageHandler ? ) { let url = `$/GetClusterVersion` ; return this . get ( this . getApiUrl ( url , RestClient . apiVersion64 ) , "Get cluster version" , messageHandler ) ; } private getEvents < T extends FabricEventBase > ( eventType , url , startTime ? , endTime ? , messageHandler ? ) { let apiUrl = url ; if ( startTime && endTime ) { apiUrl = apiUrl + "?starttimeutc=" + startTime . toISOString ( ) . substr ( 0 , 19 ) + "Z" + "&endtimeutc=" + endTime . toISOString ( ) . substr ( 0 , 19 ) + "Z" ; } let fullUrl = this . getApiUrl ( apiUrl , RestClient . apiVersion72 , null , true ) ; return this . get < IRawList < { } > > ( fullUrl , null , messageHandler ) . then ( response => { return new EventsResponseAdapter ( eventType ) . getEvents ( response . data ) ; } ) ; } param path param apiVersion private getApiUrl ( path , apiVersion = RestClient . defaultApiVersion , continuationToken ? , skipCacheToken ? ) { return StandaloneIntegration . clusterUrl + `/${ path }${ path . indexOf ( "?" ) === - 1 ? "?" : "&" }api-version=${ apiVersion ? apiVersion : RestClient . defaultApiVersion }${ skipCacheToken === true ? "" : `&_cacheToken=${ this . cacheAllowanceToken }` }${ continuationToken ? `&ContinuationToken=${ continuationToken }` : "" }` ; } private getApiUrl2 ( path , apiVersion = RestClient . defaultApiVersion , continuationToken ? , skipCacheToken ? , startDate ? , endDate ? , maxResults ? , latest ? ) { let 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 ? ) { let appUrl = this . getApiUrl ( url , apiVersion , continuationToken , false ) ; return this . get < IRawCollection < T > > ( appUrl , apiDesc , messageHandler ) . then ( response => { if ( response . data . ContinuationToken ) { return this . getFullCollection < T > ( url , apiDesc , apiVersion , messageHandler , response . data . ContinuationToken ) . then ( items => { return _ . union ( response . data . Items , items ) ; } ) ; } return response . data . Items ; } ) . catch ( err => { return [ ] ; } ) ; } private getFullCollection2 < T > ( url , apiDesc , apiVersion ? , messageHandler ? , continuationToken ? , startDate ? , endDate ? , maxResults ? , latest ? ) { let appUrl = this . getApiUrl2 ( url , apiVersion , continuationToken , false , startDate , endDate , maxResults , latest ) ; return this . get < IRawCollection < T > > ( appUrl , apiDesc , messageHandler ) . then ( response => { if ( response . data . ContinuationToken ) { return this . getFullCollection < T > ( url , apiDesc , apiVersion , messageHandler , response . data . ContinuationToken ) . then ( items => { return _ . union ( response . data . Items , items ) ; } ) ; } return response . data . Items ; } ) . catch ( err => { return [ ] ; } ) ; } private get < T > ( url , apiDesc , messageHandler ? ) { let result = this . wrapInCallbacks < T > ( ( ) => this . httpClient . getAsync ( url ) ) ; if ( ! messageHandler ) { messageHandler = ResponseMessageHandlers . getResponseMessageHandler ; } this . handleResponse ( apiDesc , result , messageHandler ) ; return result ; } private post < T > ( url , apiDesc , data ? , messageHandler ? ) { let result = this . wrapInCallbacks < T > ( ( ) => this . httpClient . postAsync ( url , data ) ) ; if ( ! messageHandler ) { messageHandler = ResponseMessageHandlers . postResponseMessageHandler ; } this . handleResponse ( apiDesc , result , messageHandler ) ; return result ; } private put < T > ( url , apiDesc , data ? , messageHandler ? ) { let result = this . wrapInCallbacks < T > ( ( ) => this . httpClient . putAsync ( url , data ) ) ; if ( ! messageHandler ) { messageHandler = ResponseMessageHandlers . putResponseMessageHandler ; } this . handleResponse ( apiDesc , result , messageHandler ) ; return result ; } private delete < T > ( url , apiDesc , messageHandler ? ) { let result = this . wrapInCallbacks < T > ( ( ) => this . httpClient . deleteAsync ( url ) ) ; if ( ! messageHandler ) { messageHandler = ResponseMessageHandlers . deleteResponseMessageHandler ; } this . handleResponse ( apiDesc , result , messageHandler ) ; return result ; } private handleResponse ( apiDesc , resultPromise , messageHandler ? ) { resultPromise . then ( ( response ) => { let message = messageHandler . getSuccessMessage ( apiDesc , response ) ; if ( message ) { this . message . showMessage ( message , MessageSeverity . Info ) ; } } , ( response ) => { let message = messageHandler . getErrorMessage ( apiDesc , response ) ; if ( message ) { this . message . showMessage ( message , MessageSeverity . Err ) ; } } ) ; } private wrapInCallbacks < T > ( operation ) { this . requestCount ++ ; let promise = operation ( ) ; promise . finally ( ( ) => { this . requestCount -- ; } ) ; return promise ; } } ( function ( ) { const module = angular . module ( "restClientService" , [ "messages" , "httpService" ] ) ; module . factory ( "restClient" , [ "httpClient" , "message" , ( httpClient , message ) => new RestClient ( httpClient , message ) ] ) ; } ) ( ) ; }