Class: AppAbstract

Inherits:
Object
  • Object
show all
Includes:
CloudmunchService, Util
Defined in:
lib/cloudmunch_Ruby_sdk_v2/AppAbstract.rb

Constant Summary collapse

@@config =

@@config_path = ENV+“/sdk_config.json”

nil

Instance Method Summary collapse

Methods included from Util

generateReport, getJSONArgs, getJSONArgsTEMP, getTemplate, getUrlForViewCards, log, logClose, logInit, logIt, openJSONFile

Methods included from CloudmunchService

#createInsight, #createInsightDataStore, #createInsightDataStoreExtract, #createInsightReport, #createInsightReportCard, #createInsightReportKeyMetric, #deleteCloudmunchData, #deleteCloudmunchDataBKUP, #generateServerURL, #getCloudmunchData, getCustomDataContext, getDataContext, #getDataStoreID, #getExtractID, #getInsightDataStoreExtracts, #getInsightDataStores, #getInsightReportCards, #getInsightReportKeyMetrics, #getInsightReports, #getInsights, #getKeyMetricID, #getReportCardID, #getReportID, http_get, http_post, #parseResponse, putCustomDataContext, #updateCloudmunchData, updateDataContext, #updateInsight, #updateInsightDataStoreExtract, #updateInsightReport, #updateInsightReportCard, #updateInsightReportKeyMetric

Constructor Details

#initialize(param = nil) ⇒ AppAbstract

Returns a new instance of AppAbstract.



16
17
18
# File 'lib/cloudmunch_Ruby_sdk_v2/AppAbstract.rb', line 16

def initialize(param = nil)
    @domain, @project, @logfile = "", "", ""
end

Instance Method Details

#cleanupAppObject



142
143
144
145
# File 'lib/cloudmunch_Ruby_sdk_v2/AppAbstract.rb', line 142

def cleanupApp()
   log("INFO", "\nExiting app")
   #puts "cleanupApp from AppAbstract"
end

#createAppContextObject



57
58
59
60
61
# File 'lib/cloudmunch_Ruby_sdk_v2/AppAbstract.rb', line 57

def createAppContext()

    @appContext = AppContext.new(@var_input)
    
end

#generateReport(reportFilename, reportString) ⇒ Object



73
74
75
# File 'lib/cloudmunch_Ruby_sdk_v2/AppAbstract.rb', line 73

def generateReport(reportFilename, reportString)
    Util.generateReport(reportFilename, reportString)
end

#getAppContextObject



84
85
86
# File 'lib/cloudmunch_Ruby_sdk_v2/AppAbstract.rb', line 84

def getAppContext()
    return @appContext
end

#getCloudmunchServiceObject



63
64
65
66
67
68
# File 'lib/cloudmunch_Ruby_sdk_v2/AppAbstract.rb', line 63

def getCloudmunchService()
    # @cloudmunchservice = @cloudmunchservice ? @cloudmunchservice : CloudmunchService.new(@var_input)
#        @cloudmunchservice = @cloudmunchservice ? @cloudmunchservice : CloudmunchService.initialize(@appContext)
    @cloudmunchservice = self.extend(CloudmunchService)
    return @cloudmunchservice
end

#getCMContext(context) ⇒ Object



114
115
116
117
118
119
120
# File 'lib/cloudmunch_Ruby_sdk_v2/AppAbstract.rb', line 114

def getCMContext(context)
    begin
        return @@config[context+"_context"]
    rescue
        return false
    end
end

#getDataContextFromCMDB(param) ⇒ Object



88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/cloudmunch_Ruby_sdk_v2/AppAbstract.rb', line 88

def getDataContextFromCMDB(param)
    appContext = getAppContext()
    params = {
        "username" => @@config['username'],
        "customcontext" => param["job"] + "_" + param["context"],
        "action" => "listcustomcontext"
    }
    param.delete("context")
    params = param.merge(params)

    return CloudmunchService.getDataContext(appContext.get_data('masterurl'), @@config["endpoint"], params)
end

#getIntegrationDetails(param = nil) ⇒ Object



77
78
79
80
81
82
# File 'lib/cloudmunch_Ruby_sdk_v2/AppAbstract.rb', line 77

def getIntegrationDetails(param = nil)
    #@json_input = @json_input ? @json_input : getJSONArgs()
    serviceProvider = ServiceProvider.new(@json_input["providername"])
    serviceProvider.load_data(@integration_input)
    return serviceProvider
end

#getJSONArgsObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/cloudmunch_Ruby_sdk_v2/AppAbstract.rb', line 38

def getJSONArgs()
  jsonin = nil
  varin=nil
  integrations=nil
  loop { case ARGV[0]
      when '-jsoninput' then  ARGV.shift; jsonin = ARGV.shift
      when '-variables' then  ARGV.shift; varin = ARGV.shift
      when '-integrations' then  ARGV.shift; integrations = ARGV.shift

      when /^-/ then  usage("Unknown option: #{ARGV[0].inspect}")
      else break
  end; }
    @json_input = JSON.load(jsonin)
    @var_input =JSON.load(varin)
    @integration_input=JSON.load(integrations)
    createAppContext();
    return @json_input
end

#getTemplate(template_name) ⇒ Object



122
123
124
125
126
127
128
# File 'lib/cloudmunch_Ruby_sdk_v2/AppAbstract.rb', line 122

def getTemplate(template_name)
    begin
        Util.getTemplate(template_name)
    rescue
        return false
    end
end

#initializeAppObject



134
135
136
# File 'lib/cloudmunch_Ruby_sdk_v2/AppAbstract.rb', line 134

def initializeApp()
    #puts "initializeApp from AppAbstract"
end

#log(level, logString) ⇒ Object



26
27
28
29
30
31
# File 'lib/cloudmunch_Ruby_sdk_v2/AppAbstract.rb', line 26

def log(level,logString)
    if @logger.nil?
        logInit("DEBUG")
    end     
    Util.logIt(@logger, @log_level, level.to_s.downcase, logString)
end

#logCloseObject



34
35
36
# File 'lib/cloudmunch_Ruby_sdk_v2/AppAbstract.rb', line 34

def logClose()
    Util.logClose(@logger)
end

#logInit(log_level) ⇒ Object



21
22
23
24
# File 'lib/cloudmunch_Ruby_sdk_v2/AppAbstract.rb', line 21

def logInit(log_level)
    @logger = @logger ? @logger : Util.logInit()
    @log_level = log_level
end

#openJSONFile(fileNameWithPath) ⇒ Object



69
70
71
# File 'lib/cloudmunch_Ruby_sdk_v2/AppAbstract.rb', line 69

def openJSONFile(fileNameWithPath)
    Util.openJSONFile(fileNameWithPath)
end

#processObject



138
139
140
# File 'lib/cloudmunch_Ruby_sdk_v2/AppAbstract.rb', line 138

def process()
    #puts "process func from AppAbstract"
end

#startObject



147
148
149
150
151
152
153
# File 'lib/cloudmunch_Ruby_sdk_v2/AppAbstract.rb', line 147

def start()
    # load_config is commented out as this config file is not required now
    #load_config()
    initializeApp()
    process()
    cleanupApp()
end

#updateDataContextToCMDB(param) ⇒ Object



101
102
103
104
105
106
107
108
109
110
111
# File 'lib/cloudmunch_Ruby_sdk_v2/AppAbstract.rb', line 101

def updateDataContextToCMDB(param)
    appContext = getAppContext()
    params = {
        "username" => @@config['username'],
        "customcontext" => param["job"] + "_" + param["context"],
        "action" => "updatecustomcontext"
    }
    param.delete("context")
    params = param.merge(params)
    return CloudmunchService.updateDataContext(appContext.get_data('masterurl'), @@config['endpoint'], params)
end