Class: AppAbstract

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

Constant Summary collapse

@@config_path =
ENV["SDK_CONFIG_PATH"]+"/sdk_config.json"
@@config =
nil

Instance Method Summary collapse

Methods included from Util

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

Methods included from CloudmunchService

getCustomDataContext, getDataContext, http_get, http_post, putCustomDataContext, updateDataContext

Constructor Details

#initialize(param = nil) ⇒ AppAbstract

Returns a new instance of AppAbstract.



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

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

Instance Method Details

#cleanupAppObject



109
110
111
112
# File 'lib/cloudmunch_sdk/AppAbstract.rb', line 109

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

#generateReport(reportFilename, reportString) ⇒ Object



46
47
48
# File 'lib/cloudmunch_sdk/AppAbstract.rb', line 46

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

#getAppContext(param = nil) ⇒ Object



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

def getAppContext(param = nil)
    @json_input = @json_input ? @json_input : getJSONArgs()
    appContext = AppContext.new(@json_input)
    return appContext
end

#getCMContext(context) ⇒ Object



89
90
91
92
93
94
95
# File 'lib/cloudmunch_sdk/AppAbstract.rb', line 89

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

#getDataContextFromCMDB(param) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/cloudmunch_sdk/AppAbstract.rb', line 63

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

#getJSONArgsObject



38
39
40
# File 'lib/cloudmunch_sdk/AppAbstract.rb', line 38

def getJSONArgs()
    @json_input = Util.getJSONArgs()
end

#getServiceProvider(param = nil) ⇒ Object



50
51
52
53
54
55
# File 'lib/cloudmunch_sdk/AppAbstract.rb', line 50

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

#initializeAppObject



101
102
103
# File 'lib/cloudmunch_sdk/AppAbstract.rb', line 101

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

#log(level, logString) ⇒ Object



26
27
28
29
30
31
# File 'lib/cloudmunch_sdk/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_sdk/AppAbstract.rb', line 34

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

#logInit(log_level) ⇒ Object



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

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

#openJSONFile(fileNameWithPath) ⇒ Object



42
43
44
# File 'lib/cloudmunch_sdk/AppAbstract.rb', line 42

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

#processObject



105
106
107
# File 'lib/cloudmunch_sdk/AppAbstract.rb', line 105

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

#startObject



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

def start()
    load_config()
    initializeApp()
    process()
    cleanupApp()
end

#updateDataContextToCMDB(param) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
# File 'lib/cloudmunch_sdk/AppAbstract.rb', line 76

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