% HPCServer - Scheduler Component for Microsoft HPC Server Schedulers
 
%   Copyright 2011-2015 The MathWorks, Inc.

% TODO:doc properties
% NB This class is hidden for now as the Profiles API is not yet documented
classdef (Hidden, Sealed) HPCServer < parallel.settings.schedulerComponent.ThirdPartyCJS
    properties (PCTGetSet, Transient, PCTConstraint = 'string')
        Host
        JobTemplate
        JobDescriptionFile
    end
    properties (PCTGetSet, Transient, PCTConstraint = 'enum:parallel.internal.types.HPCServerClusterVersion')
        ClusterVersion
    end
    properties (PCTGetSet, Transient, PCTConstraint = 'logicalscalar')
        UseSOAJobSubmission
    end
    
    methods (Hidden, Static) % Implementation of NamedNode Hidden, Static methods
        function obj = hBuildFromSettings(name, settingsNode, parentSettingsNode, varargin) 
            obj = parallel.settings.schedulerComponent.HPCServer(name, settingsNode, parentSettingsNode, varargin{:});
            % Ensure the Cluster Version gets set to the correct by using
            % the full public API to set it.
            if obj.isSet('ClusterVersion')
                obj.ClusterVersion = obj.ClusterVersion;
            end
        end
    end
    
    methods (Hidden)
        function hSetProperty(obj, props, values, varargin)
        % Override of hSetProperty to ensure that a ClusterVersion of 
        % HPCServer2008 is stored as HPCServer
            if ~iscell(props)
                props = {props};
                values = {values};
            end
            
            clusterVersionIdx = find(strcmp(props, 'ClusterVersion'), 1, 'last');
            if ~isempty(clusterVersionIdx)
                % Ensure that the cluster version always uses the default name
                % and not just any of the allowed names.
                actualVersion = parallel.internal.types.HPCServerClusterVersion.fromName(values{clusterVersionIdx});
                values{clusterVersionIdx} = actualVersion.Name;
            end
            
            hSetProperty@parallel.internal.settings.CustomSettingsGetSet(obj, props, values, varargin{:});
        end
    end

    methods (Access = private) % Constructor
        function obj = HPCServer(name, node, parentNode, varargin)
            import parallel.internal.types.SchedulerType
            obj@parallel.settings.schedulerComponent.ThirdPartyCJS(name, ...
                SchedulerType.HPCServer, node, parentNode, varargin{:});
        end
    end

    methods (Hidden) % overrides of CustomPropDisp
       function [n, f] = hCustomizeDisplay(obj, level)
            n = {'Host', 'ClusterVersion', 'UseSOAJobSubmission', ...
                'JobTemplate', 'JobDescriptionFile'};
            if nargin < 2
                f = obj.get(n);
            else
                f = cellfun(@(x) obj.get(x, level), n, 'UniformOutput', false);
            end
        end
    end
    
    methods (Access = protected) % Implementation of SchedulerComponent abstract methods
        function tf = isAlreadyDiscovered(obj, names, values)
            propsToCompare = 'Host';
            otherHost = obj.extractValuesFromNamesValues(propsToCompare, names, values);
            tf = obj.isEquivalentHost(otherHost);
        end
    end
end
%#ok<*ATUNK> custom attributes
