module Sfx { export class DataService { public systemApp : SystemApplication ; public clusterManifest : ClusterManifest ; public clusterUpgradeProgress : ClusterUpgradeProgress ; public clusterLoadInformation : ClusterLoadInformation ; public appTypeGroups : ApplicationTypeGroupCollection ; public apps : ApplicationCollection ; public nodes : NodeCollection ; public imageStore : ImageStore ; public networks : NetworkCollection ; public backupPolicies : BackupPolicyCollection ; public constructor ( public routes , public message , public telemetry , public $location , public restClient , public warnings , public storage , public $q , public $timeout , public $uibModal , public $route , public $sanitize , public $rootScope ) { this . systemApp = new SystemApplication ( this ) ; this . clusterManifest = new ClusterManifest ( this ) ; this . clusterUpgradeProgress = new ClusterUpgradeProgress ( this ) ; this . clusterLoadInformation = new ClusterLoadInformation ( this ) ; this . appTypeGroups = new ApplicationTypeGroupCollection ( this ) ; this . apps = new ApplicationCollection ( this ) ; this . nodes = new NodeCollection ( this ) ; this . imageStore = new ImageStore ( this ) ; this . networks = new NetworkCollection ( this ) ; this . backupPolicies = new BackupPolicyCollection ( this ) ; } public actionsEnabled ( ) { return this . $rootScope [ Constants . SfxReadonlyMetadataName ] !== true ; } public actionsAdvancedEnabled ( ) { return this . actionsEnabled ( ) && this . storage . getValueBoolean ( Constants . AdvancedModeKey , false ) ; } public invalidateBrowserRestResponseCache ( ) { this . restClient . invalidateBrowserRestResponseCache ( ) ; } public getClusterHealth ( eventsHealthStateFilter = HealthStateFilterFlags . Default , nodesHealthStateFilter = HealthStateFilterFlags . Default , applicationsHealthStateFilter = HealthStateFilterFlags . Default ) { return new ClusterHealth ( this , eventsHealthStateFilter , nodesHealthStateFilter , applicationsHealthStateFilter ) ; } public getClusterManifest ( forceRefresh = false , messageHandler ? ) { return this . clusterManifest . ensureInitialized ( forceRefresh , messageHandler ) ; } public getClusterUpgradeProgress ( forceRefresh = false , messageHandler ? ) { return this . clusterUpgradeProgress . ensureInitialized ( forceRefresh , messageHandler ) ; } public getClusterLoadInformation ( forceRefresh = false , messageHandler ? ) { return this . clusterLoadInformation . ensureInitialized ( forceRefresh , messageHandler ) ; } public getClusterHealthChunk ( healthDescriptor ) { return this . restClient . getClusterHealthChunk ( healthDescriptor , ResponseMessageHandlers . silentResponseMessageHandler ) . then ( ( raw ) => { return this . preprocessHealthChunkData ( raw . data ) ; } ) ; } public getInitialClusterHealthChunkQueryDescription ( ) { return { ApplicationFilters : [ { HealthStateFilter : HealthStateFilterFlags . All } ] , NodeFilters : [ { HealthStateFilter : HealthStateFilterFlags . All } ] } ; } public getSystemApp ( forceRefresh ? , messageHandler ? ) { return this . systemApp . ensureInitialized ( forceRefresh , messageHandler ) ; } public getSystemServices ( forceRefresh ? , messageHandler ? ) { return this . getSystemApp ( false , messageHandler ) . then ( app => { return app . services . ensureInitialized ( forceRefresh , messageHandler ) ; } ) ; } public getApps ( forceRefresh ? , messageHandler ? ) { return this . apps . ensureInitialized ( forceRefresh , messageHandler ) ; } public getApp ( id , forceRefresh ? , messageHandler ? ) { return this . getApps ( false , messageHandler ) . then ( collection => { return this . tryGetValidItem ( collection , id , forceRefresh , messageHandler ) ; } ) ; } public getNodes ( forceRefresh ? , messageHandler ? ) { return this . nodes . ensureInitialized ( forceRefresh , messageHandler ) ; } public getNode ( name , forceRefresh ? , messageHandler ? ) { return this . getNodes ( false , messageHandler ) . then ( collection => { return this . tryGetValidItem ( collection , name , forceRefresh , messageHandler ) ; } ) ; } public getBackupPolicies ( forceRefresh ? , messageHandler ? ) { return this . backupPolicies . ensureInitialized ( forceRefresh , messageHandler ) ; } public getBackupPolicy ( name , forceRefresh ? , messageHandler ? ) { return this . getBackupPolicies ( false , messageHandler ) . then ( collection => { return this . tryGetValidItem ( collection , name , forceRefresh , messageHandler ) ; } ) ; } public getNetwork ( networkName , forceRefresh ? , messageHandler ? ) { return this . getNetworks ( false , messageHandler ) . then ( collection => { return this . tryGetValidItem ( collection , networkName , forceRefresh , messageHandler ) ; } ) ; } public getNetworks ( forceRefresh ? , messageHandler ? ) { return this . networks . ensureInitialized ( forceRefresh , messageHandler ) ; } public getAppTypeGroups ( forceRefresh ? , messageHandler ? ) { return this . appTypeGroups . ensureInitialized ( forceRefresh , messageHandler ) ; } public getAppTypeGroup ( name , forceRefresh ? , messageHandler ? ) { return this . getAppTypeGroups ( false , messageHandler ) . then ( collection => { return this . tryGetValidItem ( collection , name , forceRefresh , messageHandler ) ; } ) ; } public getAppType ( name , version , forceRefresh ? , messageHandler ? ) { return this . getAppTypeGroup ( name , false , messageHandler ) . then ( appTypeGroup => { let filteredAppTypes = _ . filter ( appTypeGroup . appTypes , appType => appType . raw . Version === version ) ; return filteredAppTypes [ 0 ] ; } ) ; } public getServiceTypes ( appTypeName , appTypeVersion , forceRefresh ? , messageHandler ? ) { return this . getAppType ( appTypeName , appTypeVersion , false , messageHandler ) . then ( appType => { return appType . serviceTypes . ensureInitialized ( forceRefresh , messageHandler ) ; } ) ; } public getServiceType ( appTypeName , appTypeVersion , serviceTypeName , forceRefresh ? , messageHandler ? ) { return this . getServiceTypes ( appTypeName , appTypeVersion , false , messageHandler ) . then ( collection => { return this . tryGetValidItem ( collection , serviceTypeName , forceRefresh , messageHandler ) ; } ) ; } public getServices ( appId , forceRefresh ? , messageHandler ? ) { let getAppPromise = appId === Constants . SystemAppId ? this . getSystemApp ( false , messageHandler ) : this . getApp ( appId , false , messageHandler ) ; return getAppPromise . then ( app => { return app . services . ensureInitialized ( forceRefresh , messageHandler ) ; } ) ; } public getService ( appId , serviceId , forceRefresh ? , messageHandler ? ) { return this . getServices ( appId , false , messageHandler ) . then ( collection => { return this . tryGetValidItem ( collection , IdGenerator . service ( serviceId ) , forceRefresh , messageHandler ) ; } ) ; } public getPartitions ( appId , serviceId , forceRefresh ? , messageHandler ? ) { return this . getService ( appId , serviceId , false , messageHandler ) . then ( service => { return service . partitions . ensureInitialized ( forceRefresh , messageHandler ) ; } ) ; } public getPartition ( appId , serviceId , partitionId , forceRefresh ? , messageHandler ? ) { return this . getPartitions ( appId , serviceId , false , messageHandler ) . then ( collection => { return this . tryGetValidItem ( collection , IdGenerator . partition ( partitionId ) , forceRefresh , messageHandler ) ; } ) ; } public getReplicasOnPartition ( appId , serviceId , partitionId , forceRefresh ? , messageHandler ? ) { return this . getPartition ( appId , serviceId , partitionId , false , messageHandler ) . then ( partition => { return partition . replicas . ensureInitialized ( forceRefresh , messageHandler ) ; } ) ; } public getReplicaOnPartition ( appId , serviceId , partitionId , replicaId , forceRefresh ? , messageHandler ? ) { return this . getReplicasOnPartition ( appId , serviceId , partitionId , false , messageHandler ) . then ( collection => { return this . tryGetValidItem ( collection , IdGenerator . replica ( replicaId ) , forceRefresh , messageHandler ) ; } ) ; } public getDeployedApplications ( nodeName , forceRefresh ? , messageHandler ? ) { return this . getNode ( nodeName , false , messageHandler ) . then ( node => { return node . deployedApps . ensureInitialized ( forceRefresh , messageHandler ) ; } ) ; } public getDeployedApplication ( nodeName , appId , forceRefresh ? , messageHandler ? ) { return this . getDeployedApplications ( nodeName , false , messageHandler ) . then ( collection => { return this . tryGetValidItem ( collection , IdGenerator . app ( appId ) , forceRefresh , messageHandler ) ; } ) ; } public getDeployedServicePackages ( nodeName , appId , forceRefresh ? , messageHandler ? ) { return this . getDeployedApplication ( nodeName , appId , false , messageHandler ) . then ( deployedApp => { return deployedApp . deployedServicePackages . ensureInitialized ( forceRefresh , messageHandler ) ; } ) ; } public getDeployedServicePackage ( nodeName , appId , servicePackageName , servicePackageActivationId , forceRefresh ? , messageHandler ? ) { return this . getDeployedServicePackages ( nodeName , appId , false , messageHandler ) . then ( collection => { return this . tryGetValidItem ( collection , IdGenerator . deployedServicePackage ( servicePackageName , servicePackageActivationId ) , forceRefresh , messageHandler ) ; } ) ; } public getDeployedCodePackages ( nodeName , appId , servicePackageName , servicePackageActivationId , forceRefresh ? , messageHandler ? ) { return this . getDeployedServicePackage ( nodeName , appId , servicePackageName , servicePackageActivationId , false , messageHandler ) . then ( deployedServicePackage => { return deployedServicePackage . deployedCodePackages . ensureInitialized ( forceRefresh , messageHandler ) ; } ) ; } public getDeployedCodePackage ( nodeName , appId , servicePackageName , servicePackageActivationId , codePackageName , forceRefresh ? , messageHandler ? ) { return this . getDeployedCodePackages ( nodeName , appId , servicePackageName , servicePackageActivationId , false , messageHandler ) . then ( collection => { return this . tryGetValidItem ( collection , IdGenerator . deployedCodePackage ( codePackageName ) , forceRefresh , messageHandler ) ; } ) ; } public getDeployedReplicas ( nodeName , appId , servicePackageName , servicePackageActivationId , forceRefresh ? , messageHandler ? ) { return this . getDeployedServicePackage ( nodeName , appId , servicePackageName , servicePackageActivationId , false , messageHandler ) . then ( deployedServicePackage => { return deployedServicePackage . deployedReplicas . ensureInitialized ( forceRefresh , messageHandler ) ; } ) ; } public getDeployedReplica ( nodeName , appId , servicePackageName , servicePackageActivationId , partitionId , forceRefresh ? , messageHandler ? ) { return this . getDeployedReplicas ( nodeName , appId , servicePackageName , servicePackageActivationId , false , messageHandler ) . then ( collection => { return this . tryGetValidItem ( collection , IdGenerator . deployedReplica ( partitionId ) , forceRefresh , messageHandler ) ; } ) ; } public createClusterEventList ( ) { return new ClusterEventList ( this ) ; } public createNodeEventList ( nodeName ? ) { return new NodeEventList ( this , nodeName ) ; } public createApplicationEventList ( applicationId ? ) { return new ApplicationEventList ( this , applicationId ) ; } public createServiceEventList ( serviceId ? ) { return new ServiceEventList ( this , serviceId ) ; } public createPartitionEventList ( partitionId ? ) { return new PartitionEventList ( this , partitionId ) ; } public createReplicaEventList ( partitionId , replicaId ? ) { return new ReplicaEventList ( this , partitionId , replicaId ) ; } public createCorrelatedEventList ( eventInstanceId ) { return new CorrelatedEventList ( this , eventInstanceId ) ; } private tryGetValidItem < T extends IDataModel < any > > ( collection , uniqueId , forceRefresh ? , messageHandler ? ) { let item = collection . find ( uniqueId ) ; if ( item ) { return item . ensureInitialized ( forceRefresh , messageHandler ) ; } else { return this . $q . reject ( ) ; } } private preprocessHealthChunkData ( clusterHealthChunk ) { clusterHealthChunk . SystemApplicationHealthStateChunk = _ . first ( _ . remove ( clusterHealthChunk . ApplicationHealthStateChunks . Items , appHealthStateChunk => appHealthStateChunk . ApplicationName === Constants . SystemAppName ) ) ; let deployedApps = [ ] ; _ . forEach ( clusterHealthChunk . ApplicationHealthStateChunks . Items , appHealthStateChunk => _ . forEach ( appHealthStateChunk . DeployedApplicationHealthStateChunks . Items , deployedApp => { deployedApp . ApplicationName = appHealthStateChunk . ApplicationName ; deployedApps . push ( deployedApp ) ; } ) ) ; let nodeDeployedAppsGroups = _ . groupBy ( deployedApps , deployedApp => deployedApp . NodeName ) ; _ . forEach ( nodeDeployedAppsGroups , ( group , key ) => { let nodeHealthChunk = _ . find ( clusterHealthChunk . NodeHealthStateChunks . Items , chunk => chunk . NodeName === key ) ; if ( nodeHealthChunk ) { nodeHealthChunk . DeployedApplicationHealthStateChunks = { Items : group , TotalCount : group . length } ; } } ) ; _ . forEach ( clusterHealthChunk . NodeHealthStateChunks . Items , nodeHealthChunk => { if ( ! nodeHealthChunk . DeployedApplicationHealthStateChunks ) { nodeHealthChunk . DeployedApplicationHealthStateChunks = { Items : [ ] , TotalCount : 0 } ; } } ) ; return clusterHealthChunk ; } } ( function ( ) { let module = angular . module ( "dataService" , [ "routes" , "messages" , "ui.bootstrap" , "ngSanitize" , "restClientService" , "StatusWarningService" , "storageService" ] ) ; module . factory ( "data" , [ "routes" , "message" , "telemetry" , "$location" , "restClient" , "warnings" , "storage" , "$q" , "$timeout" , "$uibModal" , "$route" , "$sanitize" , "$rootScope" , ( routes , message , telemetry , $location , restClient , warnings , storage , $q , $timeout , $uibModal , $route , $sanitize , $rootScope ) => new DataService ( routes , message , telemetry , $location , restClient , warnings , storage , $q , $timeout , $uibModal , $route , $sanitize , $rootScope ) ] ) ; module . run ( [ "$rootScope" , "data" , function ( $rootScope , data ) { $rootScope . $on ( "$routeChangeSuccess" , function ( event , next , current ) { data . invalidateBrowserRestResponseCache ( ) ; } ) ; $rootScope [ "SfxVersion" ] = VersionInfo . Version ; $rootScope [ "SfxBuild" ] = VersionInfo . Build ; $rootScope [ "ShowPreviewWarning" ] = VersionInfo . IsPreview ; } ] ) ; } ) ( ) ; }