Statistics
| Branch: | Tag: | Revision:

one / include / MarketPlaceAppPool.h @ 6368bb51

History | View | Annotate | Download (6.2 KB)

1
/* -------------------------------------------------------------------------- */
2
/* Copyright 2002-2017, OpenNebula Project, OpenNebula Systems                */
3
/*                                                                            */
4
/* Licensed under the Apache License, Version 2.0 (the "License"); you may    */
5
/* not use this file except in compliance with the License. You may obtain    */
6
/* a copy of the License at                                                   */
7
/*                                                                            */
8
/* http://www.apache.org/licenses/LICENSE-2.0                                 */
9
/*                                                                            */
10
/* Unless required by applicable law or agreed to in writing, software        */
11
/* distributed under the License is distributed on an "AS IS" BASIS,          */
12
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   */
13
/* See the License for the specific language governing permissions and        */
14
/* limitations under the License.                                             */
15
/* -------------------------------------------------------------------------- */
16

    
17
#ifndef MARKETPLACEAPP_POOL_H_
18
#define MARKETPLACEAPP_POOL_H_
19

    
20
#include "MarketPlaceApp.h"
21

    
22
class SqlDB;
23

    
24
class MarketPlaceAppPool : public PoolSQL
25
{
26
public:
27
    MarketPlaceAppPool(SqlDB * db):PoolSQL(db, MarketPlaceApp::table){};
28

    
29
    ~MarketPlaceAppPool(){};
30

    
31
    /* ---------------------------------------------------------------------- */
32
    /* Methods for DB management                                              */
33
    /* ---------------------------------------------------------------------- */
34

    
35
    /**
36
     *  Allocates a new MarketPlaceApp, writing it in the pool database.
37
     *    @param uid the user id of the MarketPlace owner
38
     *    @param gid the id of the group this object is assigned to
39
     *    @param uname name of the user
40
     *    @param gname name of the group
41
     *    @param umask permissions umask
42
     *    @param apptemplate MarketPlaceApp definition template
43
     *    @param mp_id of the MarketPlace to store de App
44
     *    @param mp_name of the MarketPlace
45
     *    @param oid the id assigned to the MarketPlace
46
     *    @param error_str Returns the error reason, if any
47
     *
48
     *    @return the oid assigned to the object, -1 in case of failure
49
     */
50
    int allocate(
51
            int                uid,
52
            int                gid,
53
            const std::string& uname,
54
            const std::string& gname,
55
            int                umask,
56
            MarketPlaceAppTemplate * apptemplate,
57
            int                mp_id,
58
            const std::string& mp_name,
59
            int *              oid,
60
            std::string&       error_str);
61

    
62
    /**
63
     *  Drops the MarketPlaceApp from the data base. The object mutex SHOULD be
64
     *  locked.
65
     *    @param objsql a pointer to the MarketPlace object
66
     *    @param error_msg Error reason, if any
67
     *    @return 0 on success, -1 DB error
68
     */
69
    int drop(PoolObjectSQL * objsql, std::string& error_msg);
70

    
71
    /**
72
     *  Imports an app into the marketplace, as reported by the monitor driver
73
     *    @param template to generate app with the from_template64 function
74
     *    @param mp_id of the MarketPlace to store de App
75
     *    @param mp_name of the MarketPlace
76
     *    @param app_id of the imported app
77
     *    @param error_str Returns the error reason, if any
78
     *
79
     *    @return the oid assigned to the object, -1 in case of failure, -2
80
     *    already imported
81
     */
82
    int import(const std::string& t64, int mp_id, const std::string& mp_name,
83
            int& app_id, std::string& error_str);
84

    
85
    /**
86
     *  Function to get a MarketPlaceApp from the pool
87
     *    @param oid MarketPlaceApp unique id
88
     *    @param lock locks the MarketPlaceApp mutex
89
     *    @return a pointer to the MarketPlaceApp, 0 if not loaded
90
     */
91
    MarketPlaceApp * get(int oid, bool lock)
92
    {
93
        return static_cast<MarketPlaceApp *>(PoolSQL::get(oid,lock));
94
    };
95

    
96
    /**
97
     *  Gets an object from the pool (if needed the object is loaded from the
98
     *  database).
99
     *   @param name of the object
100
     *   @param uid id of owner
101
     *   @param lock locks the object if true
102
     *
103
     *   @return a pointer to the object, 0 in case of failure
104
     */
105
    MarketPlaceApp * get(const std::string& name, int uid, bool lock)
106
    {
107
        return static_cast<MarketPlaceApp *>(PoolSQL::get(name, uid, lock));
108
    };
109

    
110
    /**
111
     *  Bootstraps the database table(s) associated to the MarketPlace pool
112
     *    @return 0 on success
113
     */
114
    static int bootstrap(SqlDB * _db)
115
    {
116
        return MarketPlaceApp::bootstrap(_db);
117
    };
118

    
119
    /**
120
     *  Dumps the MarketPlace pool in XML format. A filter can be also added to
121
     *  the query
122
     *  @param oss the output stream to dump the pool contents
123
     *  @param where filter for the objects, defaults to all
124
     *  @param limit parameters used for pagination
125
     *
126
     *  @return 0 on success
127
     */
128
    int dump(std::ostringstream& oss, const std::string& where,
129
                const std::string& limit)
130
    {
131
        return PoolSQL::dump(oss, "MARKETPLACEAPP_POOL", MarketPlaceApp::table,
132
                where, limit);
133
    };
134

    
135
    /** Update a particular MarketPlaceApp
136
     *    @param zone pointer to Zone
137
     *    @return 0 on success
138
     */
139
    int update(PoolObjectSQL * objsql);
140

    
141
    /**
142
     *  Factory method to produce objects
143
     *    @return a pointer to the new object
144
     */
145
    PoolObjectSQL * create()
146
    {
147
        return new MarketPlaceApp(-1,-1,"","", 0, 0);
148
    };
149

    
150
    /**
151
     * Check an element into map
152
     *   @param map_id of the app
153
     *   @return true if the app has to be deleted
154
     */
155
    bool test_map_check(int map_id);
156

    
157
    /**
158
     *  Resets the counter of missing monitors of an app
159
     *    @param app_id of the app
160
     */
161
    void reset_map_check(int app_id);
162

    
163
private:
164

    
165
    /**
166
     *  Hash to store the number of times an app was missing from monitor data
167
     */
168
    map<int, int> map_check;
169

    
170
    /**
171
     *  Max number of monitor that an app may be missing before deleting it
172
     */
173
    static const int MAX_MISSING_MONITORS;
174
};
175

    
176
#endif /*MARKETPLACE_POOL_H_*/