% MJSComputeCloudFinder - Find MJSComputeCloud clusters 

%   Copyright 2015-2020 The MathWorks, Inc.

classdef MJSComputeCloudFinder
    properties (Constant)
        % Use InstutilResourceKeys for the current MATLAB release string.
        % This string is the same as the one Cloud Center uses to work with MHLM.
        % For a cluster to be compatible, its release version string must match this one.
        CurrentRelease = parallel.internal.cloud.currentCloudCenterClient().MatlabReleaseVersion;

    end
    
    methods (Static)
        function clusterInfos = getAllClusters()
            clusterInfos = parallel.internal.cloud.discoverCloudClusters();
        end
        
        function clusterInfos = getCompatibleClusters()
            clusterInfos = parallel.internal.cluster.MJSComputeCloudFinder.getAllClusters();
            isCompatible = parallel.internal.cluster.MJSComputeCloudFinder.isCompatibleCluster(clusterInfos);
            clusterInfos = clusterInfos(isCompatible);
        end
        
        function tf = isCompatibleCluster(clusterInfos)
            tf = arrayfun(@(x) startsWith(x.MatlabReleaseVersion,...
                parallel.internal.cluster.MJSComputeCloudFinder.CurrentRelease), clusterInfos);
        end
    end
end
