Compare commits
109 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
7fd44a55cb | ||
|
f3df1e42b9 | ||
|
4c0c75be91 | ||
|
e6ca520a88 | ||
|
2d249f38ff | ||
|
4a17d0c07d | ||
|
1d6b9db5f9 | ||
|
d249bcdf94 | ||
|
66413e15bb | ||
|
828efb4c98 | ||
|
06e048165e | ||
|
c47ba64d49 | ||
|
e4860ff67e | ||
|
5f05b73366 | ||
|
20ce1f5ef3 | ||
|
4de43a301c | ||
|
1a55212378 | ||
|
c34e5579fc | ||
|
cc8fc2df21 | ||
|
cd902c6688 | ||
|
84deb17e37 | ||
|
158d3aacc8 | ||
|
55a25aba83 | ||
|
719fa239e0 | ||
|
72d5c64c2d | ||
|
e45fefe883 | ||
|
8e82b87fb3 | ||
|
59a1b52242 | ||
|
3c54f3d39e | ||
|
56f81fb30e | ||
|
73fce1d8fb | ||
|
3e7f8513eb | ||
|
1561d0c81e | ||
|
847ef2e95c | ||
|
dbcd9cf004 | ||
|
9654d59fc0 | ||
|
b432266486 | ||
|
73602b6c3d | ||
|
9f5e6d6018 | ||
|
62705cc9b9 | ||
|
69fe3f8d76 | ||
|
556d711ab6 | ||
|
17749c6c0b | ||
|
84024a143e | ||
|
ae49c40ea5 | ||
|
b90ffbc4f0 | ||
|
ba6ac86bff | ||
|
5d9c922b26 | ||
|
208f69ae7e | ||
|
3c14c64f4a | ||
|
3bbde50f96 | ||
|
65668f5bee | ||
|
03e066c297 | ||
|
e69d5b3351 | ||
|
a39f539426 | ||
|
6724ff38fe | ||
|
c09994fd84 | ||
|
1d0b06ac4a | ||
|
7b2da3ba94 | ||
|
c5bdc96542 | ||
|
e28b87ce7b | ||
|
0efb852839 | ||
|
6dfd6058ef | ||
|
c083ce748c | ||
|
3388fcc6f3 | ||
|
91128313fc | ||
|
34212e86a5 | ||
|
2de218782f | ||
|
1a061f2d1f | ||
|
de0b910e09 | ||
|
d865ee2766 | ||
|
9d246ad180 | ||
|
2797d97537 | ||
|
a09a04e1a7 | ||
|
3f610619b5 | ||
|
c309d97623 | ||
|
93903b4938 | ||
|
3c1a84011e | ||
|
f9bfafa004 | ||
|
f26249ab8b | ||
|
4ec32bafa7 | ||
|
e621fb616a | ||
|
aaef5334ce | ||
|
be976bd8ed | ||
|
5f735b6e9d | ||
|
f490dc3555 | ||
|
cdf513c2c4 | ||
|
eba6fd4f97 | ||
|
1582654a9c | ||
|
0ac55a0ec1 | ||
|
3d58416d9b | ||
|
279090889f | ||
|
8953e2cd42 | ||
|
a48bcf25e4 | ||
|
2df71c6571 | ||
|
89a1ab3f6e | ||
|
021b461b0a | ||
|
5c9adcf597 | ||
|
92bb274d03 | ||
|
95a4acff36 | ||
|
50ea0969e6 | ||
|
6acbcb6704 | ||
|
6c9b9ea30d | ||
|
a4374602e1 | ||
|
610eb0cfda | ||
|
4f798263b1 | ||
|
a0dd8e1c42 | ||
|
754925c32c | ||
|
4956166f76 |
660
LICENSE.md
Normal file
660
LICENSE.md
Normal file
@ -0,0 +1,660 @@
|
|||||||
|
# GNU AFFERO GENERAL PUBLIC LICENSE
|
||||||
|
|
||||||
|
Version 3, 19 November 2007
|
||||||
|
|
||||||
|
Copyright (C) 2007 Free Software Foundation, Inc.
|
||||||
|
<https://fsf.org/>
|
||||||
|
|
||||||
|
Everyone is permitted to copy and distribute verbatim copies of this
|
||||||
|
license document, but changing it is not allowed.
|
||||||
|
|
||||||
|
## Preamble
|
||||||
|
|
||||||
|
The GNU Affero General Public License is a free, copyleft license for
|
||||||
|
software and other kinds of works, specifically designed to ensure
|
||||||
|
cooperation with the community in the case of network server software.
|
||||||
|
|
||||||
|
The licenses for most software and other practical works are designed
|
||||||
|
to take away your freedom to share and change the works. By contrast,
|
||||||
|
our General Public Licenses are intended to guarantee your freedom to
|
||||||
|
share and change all versions of a program--to make sure it remains
|
||||||
|
free software for all its users.
|
||||||
|
|
||||||
|
When we speak of free software, we are referring to freedom, not
|
||||||
|
price. Our General Public Licenses are designed to make sure that you
|
||||||
|
have the freedom to distribute copies of free software (and charge for
|
||||||
|
them if you wish), that you receive source code or can get it if you
|
||||||
|
want it, that you can change the software or use pieces of it in new
|
||||||
|
free programs, and that you know you can do these things.
|
||||||
|
|
||||||
|
Developers that use our General Public Licenses protect your rights
|
||||||
|
with two steps: (1) assert copyright on the software, and (2) offer
|
||||||
|
you this License which gives you legal permission to copy, distribute
|
||||||
|
and/or modify the software.
|
||||||
|
|
||||||
|
A secondary benefit of defending all users' freedom is that
|
||||||
|
improvements made in alternate versions of the program, if they
|
||||||
|
receive widespread use, become available for other developers to
|
||||||
|
incorporate. Many developers of free software are heartened and
|
||||||
|
encouraged by the resulting cooperation. However, in the case of
|
||||||
|
software used on network servers, this result may fail to come about.
|
||||||
|
The GNU General Public License permits making a modified version and
|
||||||
|
letting the public access it on a server without ever releasing its
|
||||||
|
source code to the public.
|
||||||
|
|
||||||
|
The GNU Affero General Public License is designed specifically to
|
||||||
|
ensure that, in such cases, the modified source code becomes available
|
||||||
|
to the community. It requires the operator of a network server to
|
||||||
|
provide the source code of the modified version running there to the
|
||||||
|
users of that server. Therefore, public use of a modified version, on
|
||||||
|
a publicly accessible server, gives the public access to the source
|
||||||
|
code of the modified version.
|
||||||
|
|
||||||
|
An older license, called the Affero General Public License and
|
||||||
|
published by Affero, was designed to accomplish similar goals. This is
|
||||||
|
a different license, not a version of the Affero GPL, but Affero has
|
||||||
|
released a new version of the Affero GPL which permits relicensing
|
||||||
|
under this license.
|
||||||
|
|
||||||
|
The precise terms and conditions for copying, distribution and
|
||||||
|
modification follow.
|
||||||
|
|
||||||
|
## TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
### 0. Definitions.
|
||||||
|
|
||||||
|
"This License" refers to version 3 of the GNU Affero General Public
|
||||||
|
License.
|
||||||
|
|
||||||
|
"Copyright" also means copyright-like laws that apply to other kinds
|
||||||
|
of works, such as semiconductor masks.
|
||||||
|
|
||||||
|
"The Program" refers to any copyrightable work licensed under this
|
||||||
|
License. Each licensee is addressed as "you". "Licensees" and
|
||||||
|
"recipients" may be individuals or organizations.
|
||||||
|
|
||||||
|
To "modify" a work means to copy from or adapt all or part of the work
|
||||||
|
in a fashion requiring copyright permission, other than the making of
|
||||||
|
an exact copy. The resulting work is called a "modified version" of
|
||||||
|
the earlier work or a work "based on" the earlier work.
|
||||||
|
|
||||||
|
A "covered work" means either the unmodified Program or a work based
|
||||||
|
on the Program.
|
||||||
|
|
||||||
|
To "propagate" a work means to do anything with it that, without
|
||||||
|
permission, would make you directly or secondarily liable for
|
||||||
|
infringement under applicable copyright law, except executing it on a
|
||||||
|
computer or modifying a private copy. Propagation includes copying,
|
||||||
|
distribution (with or without modification), making available to the
|
||||||
|
public, and in some countries other activities as well.
|
||||||
|
|
||||||
|
To "convey" a work means any kind of propagation that enables other
|
||||||
|
parties to make or receive copies. Mere interaction with a user
|
||||||
|
through a computer network, with no transfer of a copy, is not
|
||||||
|
conveying.
|
||||||
|
|
||||||
|
An interactive user interface displays "Appropriate Legal Notices" to
|
||||||
|
the extent that it includes a convenient and prominently visible
|
||||||
|
feature that (1) displays an appropriate copyright notice, and (2)
|
||||||
|
tells the user that there is no warranty for the work (except to the
|
||||||
|
extent that warranties are provided), that licensees may convey the
|
||||||
|
work under this License, and how to view a copy of this License. If
|
||||||
|
the interface presents a list of user commands or options, such as a
|
||||||
|
menu, a prominent item in the list meets this criterion.
|
||||||
|
|
||||||
|
### 1. Source Code.
|
||||||
|
|
||||||
|
The "source code" for a work means the preferred form of the work for
|
||||||
|
making modifications to it. "Object code" means any non-source form of
|
||||||
|
a work.
|
||||||
|
|
||||||
|
A "Standard Interface" means an interface that either is an official
|
||||||
|
standard defined by a recognized standards body, or, in the case of
|
||||||
|
interfaces specified for a particular programming language, one that
|
||||||
|
is widely used among developers working in that language.
|
||||||
|
|
||||||
|
The "System Libraries" of an executable work include anything, other
|
||||||
|
than the work as a whole, that (a) is included in the normal form of
|
||||||
|
packaging a Major Component, but which is not part of that Major
|
||||||
|
Component, and (b) serves only to enable use of the work with that
|
||||||
|
Major Component, or to implement a Standard Interface for which an
|
||||||
|
implementation is available to the public in source code form. A
|
||||||
|
"Major Component", in this context, means a major essential component
|
||||||
|
(kernel, window system, and so on) of the specific operating system
|
||||||
|
(if any) on which the executable work runs, or a compiler used to
|
||||||
|
produce the work, or an object code interpreter used to run it.
|
||||||
|
|
||||||
|
The "Corresponding Source" for a work in object code form means all
|
||||||
|
the source code needed to generate, install, and (for an executable
|
||||||
|
work) run the object code and to modify the work, including scripts to
|
||||||
|
control those activities. However, it does not include the work's
|
||||||
|
System Libraries, or general-purpose tools or generally available free
|
||||||
|
programs which are used unmodified in performing those activities but
|
||||||
|
which are not part of the work. For example, Corresponding Source
|
||||||
|
includes interface definition files associated with source files for
|
||||||
|
the work, and the source code for shared libraries and dynamically
|
||||||
|
linked subprograms that the work is specifically designed to require,
|
||||||
|
such as by intimate data communication or control flow between those
|
||||||
|
subprograms and other parts of the work.
|
||||||
|
|
||||||
|
The Corresponding Source need not include anything that users can
|
||||||
|
regenerate automatically from other parts of the Corresponding Source.
|
||||||
|
|
||||||
|
The Corresponding Source for a work in source code form is that same
|
||||||
|
work.
|
||||||
|
|
||||||
|
### 2. Basic Permissions.
|
||||||
|
|
||||||
|
All rights granted under this License are granted for the term of
|
||||||
|
copyright on the Program, and are irrevocable provided the stated
|
||||||
|
conditions are met. This License explicitly affirms your unlimited
|
||||||
|
permission to run the unmodified Program. The output from running a
|
||||||
|
covered work is covered by this License only if the output, given its
|
||||||
|
content, constitutes a covered work. This License acknowledges your
|
||||||
|
rights of fair use or other equivalent, as provided by copyright law.
|
||||||
|
|
||||||
|
You may make, run and propagate covered works that you do not convey,
|
||||||
|
without conditions so long as your license otherwise remains in force.
|
||||||
|
You may convey covered works to others for the sole purpose of having
|
||||||
|
them make modifications exclusively for you, or provide you with
|
||||||
|
facilities for running those works, provided that you comply with the
|
||||||
|
terms of this License in conveying all material for which you do not
|
||||||
|
control copyright. Those thus making or running the covered works for
|
||||||
|
you must do so exclusively on your behalf, under your direction and
|
||||||
|
control, on terms that prohibit them from making any copies of your
|
||||||
|
copyrighted material outside their relationship with you.
|
||||||
|
|
||||||
|
Conveying under any other circumstances is permitted solely under the
|
||||||
|
conditions stated below. Sublicensing is not allowed; section 10 makes
|
||||||
|
it unnecessary.
|
||||||
|
|
||||||
|
### 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||||
|
|
||||||
|
No covered work shall be deemed part of an effective technological
|
||||||
|
measure under any applicable law fulfilling obligations under article
|
||||||
|
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||||
|
similar laws prohibiting or restricting circumvention of such
|
||||||
|
measures.
|
||||||
|
|
||||||
|
When you convey a covered work, you waive any legal power to forbid
|
||||||
|
circumvention of technological measures to the extent such
|
||||||
|
circumvention is effected by exercising rights under this License with
|
||||||
|
respect to the covered work, and you disclaim any intention to limit
|
||||||
|
operation or modification of the work as a means of enforcing, against
|
||||||
|
the work's users, your or third parties' legal rights to forbid
|
||||||
|
circumvention of technological measures.
|
||||||
|
|
||||||
|
### 4. Conveying Verbatim Copies.
|
||||||
|
|
||||||
|
You may convey verbatim copies of the Program's source code as you
|
||||||
|
receive it, in any medium, provided that you conspicuously and
|
||||||
|
appropriately publish on each copy an appropriate copyright notice;
|
||||||
|
keep intact all notices stating that this License and any
|
||||||
|
non-permissive terms added in accord with section 7 apply to the code;
|
||||||
|
keep intact all notices of the absence of any warranty; and give all
|
||||||
|
recipients a copy of this License along with the Program.
|
||||||
|
|
||||||
|
You may charge any price or no price for each copy that you convey,
|
||||||
|
and you may offer support or warranty protection for a fee.
|
||||||
|
|
||||||
|
### 5. Conveying Modified Source Versions.
|
||||||
|
|
||||||
|
You may convey a work based on the Program, or the modifications to
|
||||||
|
produce it from the Program, in the form of source code under the
|
||||||
|
terms of section 4, provided that you also meet all of these
|
||||||
|
conditions:
|
||||||
|
|
||||||
|
- a) The work must carry prominent notices stating that you modified
|
||||||
|
it, and giving a relevant date.
|
||||||
|
- b) The work must carry prominent notices stating that it is
|
||||||
|
released under this License and any conditions added under
|
||||||
|
section 7. This requirement modifies the requirement in section 4
|
||||||
|
to "keep intact all notices".
|
||||||
|
- c) You must license the entire work, as a whole, under this
|
||||||
|
License to anyone who comes into possession of a copy. This
|
||||||
|
License will therefore apply, along with any applicable section 7
|
||||||
|
additional terms, to the whole of the work, and all its parts,
|
||||||
|
regardless of how they are packaged. This License gives no
|
||||||
|
permission to license the work in any other way, but it does not
|
||||||
|
invalidate such permission if you have separately received it.
|
||||||
|
- d) If the work has interactive user interfaces, each must display
|
||||||
|
Appropriate Legal Notices; however, if the Program has interactive
|
||||||
|
interfaces that do not display Appropriate Legal Notices, your
|
||||||
|
work need not make them do so.
|
||||||
|
|
||||||
|
A compilation of a covered work with other separate and independent
|
||||||
|
works, which are not by their nature extensions of the covered work,
|
||||||
|
and which are not combined with it such as to form a larger program,
|
||||||
|
in or on a volume of a storage or distribution medium, is called an
|
||||||
|
"aggregate" if the compilation and its resulting copyright are not
|
||||||
|
used to limit the access or legal rights of the compilation's users
|
||||||
|
beyond what the individual works permit. Inclusion of a covered work
|
||||||
|
in an aggregate does not cause this License to apply to the other
|
||||||
|
parts of the aggregate.
|
||||||
|
|
||||||
|
### 6. Conveying Non-Source Forms.
|
||||||
|
|
||||||
|
You may convey a covered work in object code form under the terms of
|
||||||
|
sections 4 and 5, provided that you also convey the machine-readable
|
||||||
|
Corresponding Source under the terms of this License, in one of these
|
||||||
|
ways:
|
||||||
|
|
||||||
|
- a) Convey the object code in, or embodied in, a physical product
|
||||||
|
(including a physical distribution medium), accompanied by the
|
||||||
|
Corresponding Source fixed on a durable physical medium
|
||||||
|
customarily used for software interchange.
|
||||||
|
- b) Convey the object code in, or embodied in, a physical product
|
||||||
|
(including a physical distribution medium), accompanied by a
|
||||||
|
written offer, valid for at least three years and valid for as
|
||||||
|
long as you offer spare parts or customer support for that product
|
||||||
|
model, to give anyone who possesses the object code either (1) a
|
||||||
|
copy of the Corresponding Source for all the software in the
|
||||||
|
product that is covered by this License, on a durable physical
|
||||||
|
medium customarily used for software interchange, for a price no
|
||||||
|
more than your reasonable cost of physically performing this
|
||||||
|
conveying of source, or (2) access to copy the Corresponding
|
||||||
|
Source from a network server at no charge.
|
||||||
|
- c) Convey individual copies of the object code with a copy of the
|
||||||
|
written offer to provide the Corresponding Source. This
|
||||||
|
alternative is allowed only occasionally and noncommercially, and
|
||||||
|
only if you received the object code with such an offer, in accord
|
||||||
|
with subsection 6b.
|
||||||
|
- d) Convey the object code by offering access from a designated
|
||||||
|
place (gratis or for a charge), and offer equivalent access to the
|
||||||
|
Corresponding Source in the same way through the same place at no
|
||||||
|
further charge. You need not require recipients to copy the
|
||||||
|
Corresponding Source along with the object code. If the place to
|
||||||
|
copy the object code is a network server, the Corresponding Source
|
||||||
|
may be on a different server (operated by you or a third party)
|
||||||
|
that supports equivalent copying facilities, provided you maintain
|
||||||
|
clear directions next to the object code saying where to find the
|
||||||
|
Corresponding Source. Regardless of what server hosts the
|
||||||
|
Corresponding Source, you remain obligated to ensure that it is
|
||||||
|
available for as long as needed to satisfy these requirements.
|
||||||
|
- e) Convey the object code using peer-to-peer transmission,
|
||||||
|
provided you inform other peers where the object code and
|
||||||
|
Corresponding Source of the work are being offered to the general
|
||||||
|
public at no charge under subsection 6d.
|
||||||
|
|
||||||
|
A separable portion of the object code, whose source code is excluded
|
||||||
|
from the Corresponding Source as a System Library, need not be
|
||||||
|
included in conveying the object code work.
|
||||||
|
|
||||||
|
A "User Product" is either (1) a "consumer product", which means any
|
||||||
|
tangible personal property which is normally used for personal,
|
||||||
|
family, or household purposes, or (2) anything designed or sold for
|
||||||
|
incorporation into a dwelling. In determining whether a product is a
|
||||||
|
consumer product, doubtful cases shall be resolved in favor of
|
||||||
|
coverage. For a particular product received by a particular user,
|
||||||
|
"normally used" refers to a typical or common use of that class of
|
||||||
|
product, regardless of the status of the particular user or of the way
|
||||||
|
in which the particular user actually uses, or expects or is expected
|
||||||
|
to use, the product. A product is a consumer product regardless of
|
||||||
|
whether the product has substantial commercial, industrial or
|
||||||
|
non-consumer uses, unless such uses represent the only significant
|
||||||
|
mode of use of the product.
|
||||||
|
|
||||||
|
"Installation Information" for a User Product means any methods,
|
||||||
|
procedures, authorization keys, or other information required to
|
||||||
|
install and execute modified versions of a covered work in that User
|
||||||
|
Product from a modified version of its Corresponding Source. The
|
||||||
|
information must suffice to ensure that the continued functioning of
|
||||||
|
the modified object code is in no case prevented or interfered with
|
||||||
|
solely because modification has been made.
|
||||||
|
|
||||||
|
If you convey an object code work under this section in, or with, or
|
||||||
|
specifically for use in, a User Product, and the conveying occurs as
|
||||||
|
part of a transaction in which the right of possession and use of the
|
||||||
|
User Product is transferred to the recipient in perpetuity or for a
|
||||||
|
fixed term (regardless of how the transaction is characterized), the
|
||||||
|
Corresponding Source conveyed under this section must be accompanied
|
||||||
|
by the Installation Information. But this requirement does not apply
|
||||||
|
if neither you nor any third party retains the ability to install
|
||||||
|
modified object code on the User Product (for example, the work has
|
||||||
|
been installed in ROM).
|
||||||
|
|
||||||
|
The requirement to provide Installation Information does not include a
|
||||||
|
requirement to continue to provide support service, warranty, or
|
||||||
|
updates for a work that has been modified or installed by the
|
||||||
|
recipient, or for the User Product in which it has been modified or
|
||||||
|
installed. Access to a network may be denied when the modification
|
||||||
|
itself materially and adversely affects the operation of the network
|
||||||
|
or violates the rules and protocols for communication across the
|
||||||
|
network.
|
||||||
|
|
||||||
|
Corresponding Source conveyed, and Installation Information provided,
|
||||||
|
in accord with this section must be in a format that is publicly
|
||||||
|
documented (and with an implementation available to the public in
|
||||||
|
source code form), and must require no special password or key for
|
||||||
|
unpacking, reading or copying.
|
||||||
|
|
||||||
|
### 7. Additional Terms.
|
||||||
|
|
||||||
|
"Additional permissions" are terms that supplement the terms of this
|
||||||
|
License by making exceptions from one or more of its conditions.
|
||||||
|
Additional permissions that are applicable to the entire Program shall
|
||||||
|
be treated as though they were included in this License, to the extent
|
||||||
|
that they are valid under applicable law. If additional permissions
|
||||||
|
apply only to part of the Program, that part may be used separately
|
||||||
|
under those permissions, but the entire Program remains governed by
|
||||||
|
this License without regard to the additional permissions.
|
||||||
|
|
||||||
|
When you convey a copy of a covered work, you may at your option
|
||||||
|
remove any additional permissions from that copy, or from any part of
|
||||||
|
it. (Additional permissions may be written to require their own
|
||||||
|
removal in certain cases when you modify the work.) You may place
|
||||||
|
additional permissions on material, added by you to a covered work,
|
||||||
|
for which you have or can give appropriate copyright permission.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, for material you
|
||||||
|
add to a covered work, you may (if authorized by the copyright holders
|
||||||
|
of that material) supplement the terms of this License with terms:
|
||||||
|
|
||||||
|
- a) Disclaiming warranty or limiting liability differently from the
|
||||||
|
terms of sections 15 and 16 of this License; or
|
||||||
|
- b) Requiring preservation of specified reasonable legal notices or
|
||||||
|
author attributions in that material or in the Appropriate Legal
|
||||||
|
Notices displayed by works containing it; or
|
||||||
|
- c) Prohibiting misrepresentation of the origin of that material,
|
||||||
|
or requiring that modified versions of such material be marked in
|
||||||
|
reasonable ways as different from the original version; or
|
||||||
|
- d) Limiting the use for publicity purposes of names of licensors
|
||||||
|
or authors of the material; or
|
||||||
|
- e) Declining to grant rights under trademark law for use of some
|
||||||
|
trade names, trademarks, or service marks; or
|
||||||
|
- f) Requiring indemnification of licensors and authors of that
|
||||||
|
material by anyone who conveys the material (or modified versions
|
||||||
|
of it) with contractual assumptions of liability to the recipient,
|
||||||
|
for any liability that these contractual assumptions directly
|
||||||
|
impose on those licensors and authors.
|
||||||
|
|
||||||
|
All other non-permissive additional terms are considered "further
|
||||||
|
restrictions" within the meaning of section 10. If the Program as you
|
||||||
|
received it, or any part of it, contains a notice stating that it is
|
||||||
|
governed by this License along with a term that is a further
|
||||||
|
restriction, you may remove that term. If a license document contains
|
||||||
|
a further restriction but permits relicensing or conveying under this
|
||||||
|
License, you may add to a covered work material governed by the terms
|
||||||
|
of that license document, provided that the further restriction does
|
||||||
|
not survive such relicensing or conveying.
|
||||||
|
|
||||||
|
If you add terms to a covered work in accord with this section, you
|
||||||
|
must place, in the relevant source files, a statement of the
|
||||||
|
additional terms that apply to those files, or a notice indicating
|
||||||
|
where to find the applicable terms.
|
||||||
|
|
||||||
|
Additional terms, permissive or non-permissive, may be stated in the
|
||||||
|
form of a separately written license, or stated as exceptions; the
|
||||||
|
above requirements apply either way.
|
||||||
|
|
||||||
|
### 8. Termination.
|
||||||
|
|
||||||
|
You may not propagate or modify a covered work except as expressly
|
||||||
|
provided under this License. Any attempt otherwise to propagate or
|
||||||
|
modify it is void, and will automatically terminate your rights under
|
||||||
|
this License (including any patent licenses granted under the third
|
||||||
|
paragraph of section 11).
|
||||||
|
|
||||||
|
However, if you cease all violation of this License, then your license
|
||||||
|
from a particular copyright holder is reinstated (a) provisionally,
|
||||||
|
unless and until the copyright holder explicitly and finally
|
||||||
|
terminates your license, and (b) permanently, if the copyright holder
|
||||||
|
fails to notify you of the violation by some reasonable means prior to
|
||||||
|
60 days after the cessation.
|
||||||
|
|
||||||
|
Moreover, your license from a particular copyright holder is
|
||||||
|
reinstated permanently if the copyright holder notifies you of the
|
||||||
|
violation by some reasonable means, this is the first time you have
|
||||||
|
received notice of violation of this License (for any work) from that
|
||||||
|
copyright holder, and you cure the violation prior to 30 days after
|
||||||
|
your receipt of the notice.
|
||||||
|
|
||||||
|
Termination of your rights under this section does not terminate the
|
||||||
|
licenses of parties who have received copies or rights from you under
|
||||||
|
this License. If your rights have been terminated and not permanently
|
||||||
|
reinstated, you do not qualify to receive new licenses for the same
|
||||||
|
material under section 10.
|
||||||
|
|
||||||
|
### 9. Acceptance Not Required for Having Copies.
|
||||||
|
|
||||||
|
You are not required to accept this License in order to receive or run
|
||||||
|
a copy of the Program. Ancillary propagation of a covered work
|
||||||
|
occurring solely as a consequence of using peer-to-peer transmission
|
||||||
|
to receive a copy likewise does not require acceptance. However,
|
||||||
|
nothing other than this License grants you permission to propagate or
|
||||||
|
modify any covered work. These actions infringe copyright if you do
|
||||||
|
not accept this License. Therefore, by modifying or propagating a
|
||||||
|
covered work, you indicate your acceptance of this License to do so.
|
||||||
|
|
||||||
|
### 10. Automatic Licensing of Downstream Recipients.
|
||||||
|
|
||||||
|
Each time you convey a covered work, the recipient automatically
|
||||||
|
receives a license from the original licensors, to run, modify and
|
||||||
|
propagate that work, subject to this License. You are not responsible
|
||||||
|
for enforcing compliance by third parties with this License.
|
||||||
|
|
||||||
|
An "entity transaction" is a transaction transferring control of an
|
||||||
|
organization, or substantially all assets of one, or subdividing an
|
||||||
|
organization, or merging organizations. If propagation of a covered
|
||||||
|
work results from an entity transaction, each party to that
|
||||||
|
transaction who receives a copy of the work also receives whatever
|
||||||
|
licenses to the work the party's predecessor in interest had or could
|
||||||
|
give under the previous paragraph, plus a right to possession of the
|
||||||
|
Corresponding Source of the work from the predecessor in interest, if
|
||||||
|
the predecessor has it or can get it with reasonable efforts.
|
||||||
|
|
||||||
|
You may not impose any further restrictions on the exercise of the
|
||||||
|
rights granted or affirmed under this License. For example, you may
|
||||||
|
not impose a license fee, royalty, or other charge for exercise of
|
||||||
|
rights granted under this License, and you may not initiate litigation
|
||||||
|
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||||
|
any patent claim is infringed by making, using, selling, offering for
|
||||||
|
sale, or importing the Program or any portion of it.
|
||||||
|
|
||||||
|
### 11. Patents.
|
||||||
|
|
||||||
|
A "contributor" is a copyright holder who authorizes use under this
|
||||||
|
License of the Program or a work on which the Program is based. The
|
||||||
|
work thus licensed is called the contributor's "contributor version".
|
||||||
|
|
||||||
|
A contributor's "essential patent claims" are all patent claims owned
|
||||||
|
or controlled by the contributor, whether already acquired or
|
||||||
|
hereafter acquired, that would be infringed by some manner, permitted
|
||||||
|
by this License, of making, using, or selling its contributor version,
|
||||||
|
but do not include claims that would be infringed only as a
|
||||||
|
consequence of further modification of the contributor version. For
|
||||||
|
purposes of this definition, "control" includes the right to grant
|
||||||
|
patent sublicenses in a manner consistent with the requirements of
|
||||||
|
this License.
|
||||||
|
|
||||||
|
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||||
|
patent license under the contributor's essential patent claims, to
|
||||||
|
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||||
|
propagate the contents of its contributor version.
|
||||||
|
|
||||||
|
In the following three paragraphs, a "patent license" is any express
|
||||||
|
agreement or commitment, however denominated, not to enforce a patent
|
||||||
|
(such as an express permission to practice a patent or covenant not to
|
||||||
|
sue for patent infringement). To "grant" such a patent license to a
|
||||||
|
party means to make such an agreement or commitment not to enforce a
|
||||||
|
patent against the party.
|
||||||
|
|
||||||
|
If you convey a covered work, knowingly relying on a patent license,
|
||||||
|
and the Corresponding Source of the work is not available for anyone
|
||||||
|
to copy, free of charge and under the terms of this License, through a
|
||||||
|
publicly available network server or other readily accessible means,
|
||||||
|
then you must either (1) cause the Corresponding Source to be so
|
||||||
|
available, or (2) arrange to deprive yourself of the benefit of the
|
||||||
|
patent license for this particular work, or (3) arrange, in a manner
|
||||||
|
consistent with the requirements of this License, to extend the patent
|
||||||
|
license to downstream recipients. "Knowingly relying" means you have
|
||||||
|
actual knowledge that, but for the patent license, your conveying the
|
||||||
|
covered work in a country, or your recipient's use of the covered work
|
||||||
|
in a country, would infringe one or more identifiable patents in that
|
||||||
|
country that you have reason to believe are valid.
|
||||||
|
|
||||||
|
If, pursuant to or in connection with a single transaction or
|
||||||
|
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||||
|
covered work, and grant a patent license to some of the parties
|
||||||
|
receiving the covered work authorizing them to use, propagate, modify
|
||||||
|
or convey a specific copy of the covered work, then the patent license
|
||||||
|
you grant is automatically extended to all recipients of the covered
|
||||||
|
work and works based on it.
|
||||||
|
|
||||||
|
A patent license is "discriminatory" if it does not include within the
|
||||||
|
scope of its coverage, prohibits the exercise of, or is conditioned on
|
||||||
|
the non-exercise of one or more of the rights that are specifically
|
||||||
|
granted under this License. You may not convey a covered work if you
|
||||||
|
are a party to an arrangement with a third party that is in the
|
||||||
|
business of distributing software, under which you make payment to the
|
||||||
|
third party based on the extent of your activity of conveying the
|
||||||
|
work, and under which the third party grants, to any of the parties
|
||||||
|
who would receive the covered work from you, a discriminatory patent
|
||||||
|
license (a) in connection with copies of the covered work conveyed by
|
||||||
|
you (or copies made from those copies), or (b) primarily for and in
|
||||||
|
connection with specific products or compilations that contain the
|
||||||
|
covered work, unless you entered into that arrangement, or that patent
|
||||||
|
license was granted, prior to 28 March 2007.
|
||||||
|
|
||||||
|
Nothing in this License shall be construed as excluding or limiting
|
||||||
|
any implied license or other defenses to infringement that may
|
||||||
|
otherwise be available to you under applicable patent law.
|
||||||
|
|
||||||
|
### 12. No Surrender of Others' Freedom.
|
||||||
|
|
||||||
|
If conditions are imposed on you (whether by court order, agreement or
|
||||||
|
otherwise) that contradict the conditions of this License, they do not
|
||||||
|
excuse you from the conditions of this License. If you cannot convey a
|
||||||
|
covered work so as to satisfy simultaneously your obligations under
|
||||||
|
this License and any other pertinent obligations, then as a
|
||||||
|
consequence you may not convey it at all. For example, if you agree to
|
||||||
|
terms that obligate you to collect a royalty for further conveying
|
||||||
|
from those to whom you convey the Program, the only way you could
|
||||||
|
satisfy both those terms and this License would be to refrain entirely
|
||||||
|
from conveying the Program.
|
||||||
|
|
||||||
|
### 13. Remote Network Interaction; Use with the GNU General Public License.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, if you modify the
|
||||||
|
Program, your modified version must prominently offer all users
|
||||||
|
interacting with it remotely through a computer network (if your
|
||||||
|
version supports such interaction) an opportunity to receive the
|
||||||
|
Corresponding Source of your version by providing access to the
|
||||||
|
Corresponding Source from a network server at no charge, through some
|
||||||
|
standard or customary means of facilitating copying of software. This
|
||||||
|
Corresponding Source shall include the Corresponding Source for any
|
||||||
|
work covered by version 3 of the GNU General Public License that is
|
||||||
|
incorporated pursuant to the following paragraph.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, you have
|
||||||
|
permission to link or combine any covered work with a work licensed
|
||||||
|
under version 3 of the GNU General Public License into a single
|
||||||
|
combined work, and to convey the resulting work. The terms of this
|
||||||
|
License will continue to apply to the part which is the covered work,
|
||||||
|
but the work with which it is combined will remain governed by version
|
||||||
|
3 of the GNU General Public License.
|
||||||
|
|
||||||
|
### 14. Revised Versions of this License.
|
||||||
|
|
||||||
|
The Free Software Foundation may publish revised and/or new versions
|
||||||
|
of the GNU Affero General Public License from time to time. Such new
|
||||||
|
versions will be similar in spirit to the present version, but may
|
||||||
|
differ in detail to address new problems or concerns.
|
||||||
|
|
||||||
|
Each version is given a distinguishing version number. If the Program
|
||||||
|
specifies that a certain numbered version of the GNU Affero General
|
||||||
|
Public License "or any later version" applies to it, you have the
|
||||||
|
option of following the terms and conditions either of that numbered
|
||||||
|
version or of any later version published by the Free Software
|
||||||
|
Foundation. If the Program does not specify a version number of the
|
||||||
|
GNU Affero General Public License, you may choose any version ever
|
||||||
|
published by the Free Software Foundation.
|
||||||
|
|
||||||
|
If the Program specifies that a proxy can decide which future versions
|
||||||
|
of the GNU Affero General Public License can be used, that proxy's
|
||||||
|
public statement of acceptance of a version permanently authorizes you
|
||||||
|
to choose that version for the Program.
|
||||||
|
|
||||||
|
Later license versions may give you additional or different
|
||||||
|
permissions. However, no additional obligations are imposed on any
|
||||||
|
author or copyright holder as a result of your choosing to follow a
|
||||||
|
later version.
|
||||||
|
|
||||||
|
### 15. Disclaimer of Warranty.
|
||||||
|
|
||||||
|
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||||
|
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||||
|
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT
|
||||||
|
WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT
|
||||||
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND
|
||||||
|
PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE
|
||||||
|
DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR
|
||||||
|
CORRECTION.
|
||||||
|
|
||||||
|
### 16. Limitation of Liability.
|
||||||
|
|
||||||
|
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||||
|
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR
|
||||||
|
CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||||
|
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES
|
||||||
|
ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT
|
||||||
|
NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR
|
||||||
|
LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM
|
||||||
|
TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER
|
||||||
|
PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||||
|
|
||||||
|
### 17. Interpretation of Sections 15 and 16.
|
||||||
|
|
||||||
|
If the disclaimer of warranty and limitation of liability provided
|
||||||
|
above cannot be given local legal effect according to their terms,
|
||||||
|
reviewing courts shall apply local law that most closely approximates
|
||||||
|
an absolute waiver of all civil liability in connection with the
|
||||||
|
Program, unless a warranty or assumption of liability accompanies a
|
||||||
|
copy of the Program in return for a fee.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
## How to Apply These Terms to Your New Programs
|
||||||
|
|
||||||
|
If you develop a new program, and you want it to be of the greatest
|
||||||
|
possible use to the public, the best way to achieve this is to make it
|
||||||
|
free software which everyone can redistribute and change under these
|
||||||
|
terms.
|
||||||
|
|
||||||
|
To do so, attach the following notices to the program. It is safest to
|
||||||
|
attach them to the start of each source file to most effectively state
|
||||||
|
the exclusion of warranty; and each file should have at least the
|
||||||
|
"copyright" line and a pointer to where the full notice is found.
|
||||||
|
|
||||||
|
<one line to give the program's name and a brief idea of what it does.>
|
||||||
|
Copyright (C) <year> <name of author>
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Affero General Public License as
|
||||||
|
published by the Free Software Foundation, either version 3 of the
|
||||||
|
License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Affero General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Affero General Public License
|
||||||
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
Also add information on how to contact you by electronic and paper
|
||||||
|
mail.
|
||||||
|
|
||||||
|
If your software can interact with users remotely through a computer
|
||||||
|
network, you should also make sure that it provides a way for users to
|
||||||
|
get its source. For example, if your program is a web application, its
|
||||||
|
interface could display a "Source" link that leads users to an archive
|
||||||
|
of the code. There are many ways you could offer source, and different
|
||||||
|
solutions will be better for different programs; see section 13 for
|
||||||
|
the specific requirements.
|
||||||
|
|
||||||
|
You should also get your employer (if you work as a programmer) or
|
||||||
|
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||||
|
necessary. For more information on this, and how to apply and follow
|
||||||
|
the GNU AGPL, see <https://www.gnu.org/licenses/>.
|
@ -8,7 +8,6 @@ import (
|
|||||||
|
|
||||||
"cloud.o-forge.io/core/oc-lib/dbs"
|
"cloud.o-forge.io/core/oc-lib/dbs"
|
||||||
"cloud.o-forge.io/core/oc-lib/logs"
|
"cloud.o-forge.io/core/oc-lib/logs"
|
||||||
"cloud.o-forge.io/core/oc-lib/static"
|
|
||||||
"github.com/rs/zerolog"
|
"github.com/rs/zerolog"
|
||||||
|
|
||||||
"go.mongodb.org/mongo-driver/bson"
|
"go.mongodb.org/mongo-driver/bson"
|
||||||
@ -132,10 +131,6 @@ func (m *MongoDB) prepareDB(list_collection []string, config MongoConf) {
|
|||||||
new_collection := mngoDB.Collection(collection_name)
|
new_collection := mngoDB.Collection(collection_name)
|
||||||
if _, exists := collectionMap[collection_name]; !exists {
|
if _, exists := collectionMap[collection_name]; !exists {
|
||||||
m.createCollection(collection_name, new_collection)
|
m.createCollection(collection_name, new_collection)
|
||||||
if collection_name == "peer" {
|
|
||||||
id, p := static.GetMyLocalBsonPeer()
|
|
||||||
m.StoreOne(p, id, collection_name)
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
CollectionMap[collection_name] = new_collection
|
CollectionMap[collection_name] = new_collection
|
||||||
}
|
}
|
||||||
@ -219,7 +214,7 @@ func (m *MongoDB) UpdateMultiple(set interface{}, filter map[string]interface{},
|
|||||||
f = append(f, bson.E{Key: k, Value: v})
|
f = append(f, bson.E{Key: k, Value: v})
|
||||||
}
|
}
|
||||||
targetDBCollection := CollectionMap[collection_name]
|
targetDBCollection := CollectionMap[collection_name]
|
||||||
MngoCtx, cancel = context.WithTimeout(context.Background(), 10*time.Second)
|
MngoCtx, cancel = context.WithTimeout(context.Background(), 50*time.Second)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
res, err := targetDBCollection.UpdateMany(MngoCtx, f, dbs.InputToBson(doc, true))
|
res, err := targetDBCollection.UpdateMany(MngoCtx, f, dbs.InputToBson(doc, true))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -238,7 +233,7 @@ func (m *MongoDB) UpdateOne(set interface{}, id string, collection_name string)
|
|||||||
bson.Unmarshal(b, &doc)
|
bson.Unmarshal(b, &doc)
|
||||||
filter := bson.M{"_id": id}
|
filter := bson.M{"_id": id}
|
||||||
targetDBCollection := CollectionMap[collection_name]
|
targetDBCollection := CollectionMap[collection_name]
|
||||||
MngoCtx, cancel = context.WithTimeout(context.Background(), 10*time.Second)
|
MngoCtx, cancel = context.WithTimeout(context.Background(), 50*time.Second)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
_, err := targetDBCollection.UpdateOne(MngoCtx, filter, dbs.InputToBson(doc, true))
|
_, err := targetDBCollection.UpdateOne(MngoCtx, filter, dbs.InputToBson(doc, true))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -275,7 +270,6 @@ func (m *MongoDB) LoadOne(id string, collection_name string) (*mongo.SingleResul
|
|||||||
}
|
}
|
||||||
filter := bson.M{"_id": id}
|
filter := bson.M{"_id": id}
|
||||||
targetDBCollection := CollectionMap[collection_name]
|
targetDBCollection := CollectionMap[collection_name]
|
||||||
|
|
||||||
MngoCtx, cancel = context.WithTimeout(context.Background(), 10*time.Second)
|
MngoCtx, cancel = context.WithTimeout(context.Background(), 10*time.Second)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ func init() {
|
|||||||
{Key: "example", Value: "text"}},
|
{Key: "example", Value: "text"}},
|
||||||
})
|
})
|
||||||
|
|
||||||
IndexesMap["datacenter"] = append(IndexesMap["datacenter"], mongo.IndexModel{Keys: bson.D{
|
IndexesMap["compute"] = append(IndexesMap["compute"], mongo.IndexModel{Keys: bson.D{
|
||||||
{Key: "description", Value: "text"},
|
{Key: "description", Value: "text"},
|
||||||
{Key: "example", Value: "text"},
|
{Key: "example", Value: "text"},
|
||||||
{Key: "owner", Value: "text"}},
|
{Key: "owner", Value: "text"}},
|
||||||
|
145
entrypoint.go
145
entrypoint.go
@ -3,6 +3,7 @@ package oclib
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"runtime/debug"
|
"runtime/debug"
|
||||||
|
|
||||||
@ -11,10 +12,12 @@ import (
|
|||||||
"cloud.o-forge.io/core/oc-lib/dbs/mongo"
|
"cloud.o-forge.io/core/oc-lib/dbs/mongo"
|
||||||
"cloud.o-forge.io/core/oc-lib/logs"
|
"cloud.o-forge.io/core/oc-lib/logs"
|
||||||
"cloud.o-forge.io/core/oc-lib/models"
|
"cloud.o-forge.io/core/oc-lib/models"
|
||||||
|
"cloud.o-forge.io/core/oc-lib/models/collaborative_area"
|
||||||
|
"cloud.o-forge.io/core/oc-lib/models/collaborative_area/rules/rule"
|
||||||
"cloud.o-forge.io/core/oc-lib/models/peer"
|
"cloud.o-forge.io/core/oc-lib/models/peer"
|
||||||
"cloud.o-forge.io/core/oc-lib/models/resource_model"
|
"cloud.o-forge.io/core/oc-lib/models/resource_model"
|
||||||
|
"cloud.o-forge.io/core/oc-lib/models/resources/compute"
|
||||||
"cloud.o-forge.io/core/oc-lib/models/resources/data"
|
"cloud.o-forge.io/core/oc-lib/models/resources/data"
|
||||||
"cloud.o-forge.io/core/oc-lib/models/resources/datacenter"
|
|
||||||
"cloud.o-forge.io/core/oc-lib/models/resources/processing"
|
"cloud.o-forge.io/core/oc-lib/models/resources/processing"
|
||||||
"cloud.o-forge.io/core/oc-lib/models/resources/storage"
|
"cloud.o-forge.io/core/oc-lib/models/resources/storage"
|
||||||
w "cloud.o-forge.io/core/oc-lib/models/resources/workflow"
|
w "cloud.o-forge.io/core/oc-lib/models/resources/workflow"
|
||||||
@ -22,9 +25,9 @@ import (
|
|||||||
w2 "cloud.o-forge.io/core/oc-lib/models/workflow"
|
w2 "cloud.o-forge.io/core/oc-lib/models/workflow"
|
||||||
"cloud.o-forge.io/core/oc-lib/models/workflow_execution"
|
"cloud.o-forge.io/core/oc-lib/models/workflow_execution"
|
||||||
"cloud.o-forge.io/core/oc-lib/models/workspace"
|
"cloud.o-forge.io/core/oc-lib/models/workspace"
|
||||||
shared_workspace "cloud.o-forge.io/core/oc-lib/models/workspace/shared"
|
|
||||||
"cloud.o-forge.io/core/oc-lib/models/workspace/shared/rules/rule"
|
|
||||||
"cloud.o-forge.io/core/oc-lib/tools"
|
"cloud.o-forge.io/core/oc-lib/tools"
|
||||||
|
beego "github.com/beego/beego/v2/server/web"
|
||||||
|
"github.com/beego/beego/v2/server/web/context"
|
||||||
"github.com/goraz/onion"
|
"github.com/goraz/onion"
|
||||||
"github.com/rs/zerolog"
|
"github.com/rs/zerolog"
|
||||||
)
|
)
|
||||||
@ -36,28 +39,28 @@ type LibDataEnum int
|
|||||||
// init accessible constant to retrieve data from the database
|
// init accessible constant to retrieve data from the database
|
||||||
const (
|
const (
|
||||||
INVALID LibDataEnum = iota
|
INVALID LibDataEnum = iota
|
||||||
DATA_RESOURCE = utils.DATA_RESOURCE
|
DATA_RESOURCE = tools.DATA_RESOURCE
|
||||||
PROCESSING_RESOURCE = utils.PROCESSING_RESOURCE
|
PROCESSING_RESOURCE = tools.PROCESSING_RESOURCE
|
||||||
STORAGE_RESOURCE = utils.STORAGE_RESOURCE
|
STORAGE_RESOURCE = tools.STORAGE_RESOURCE
|
||||||
DATACENTER_RESOURCE = utils.DATACENTER_RESOURCE
|
COMPUTE_RESOURCE = tools.COMPUTE_RESOURCE
|
||||||
WORKFLOW_RESOURCE = utils.WORKFLOW_RESOURCE
|
WORKFLOW_RESOURCE = tools.WORKFLOW_RESOURCE
|
||||||
WORKFLOW = utils.WORKFLOW
|
WORKFLOW = tools.WORKFLOW
|
||||||
WORKSPACE = utils.WORKSPACE
|
WORKSPACE = tools.WORKSPACE
|
||||||
WORKFLOW_EXECUTION = utils.WORKFLOW_EXECUTION
|
WORKFLOW_EXECUTION = tools.WORKFLOW_EXECUTION
|
||||||
PEER = utils.PEER
|
PEER = tools.PEER
|
||||||
SHARED_WORKSPACE = utils.SHARED_WORKSPACE
|
SHARED_WORKSPACE = tools.COLLABORATIVE_AREA
|
||||||
RULE = utils.RULE
|
RULE = tools.RULE
|
||||||
BOOKING = utils.BOOKING
|
BOOKING = tools.BOOKING
|
||||||
)
|
)
|
||||||
|
|
||||||
// will turn into standards api hostnames
|
// will turn into standards api hostnames
|
||||||
func (d LibDataEnum) API() string {
|
func (d LibDataEnum) API() string {
|
||||||
return utils.DefaultAPI[d]
|
return tools.DefaultAPI[d]
|
||||||
}
|
}
|
||||||
|
|
||||||
// will turn into standards name
|
// will turn into standards name
|
||||||
func (d LibDataEnum) String() string {
|
func (d LibDataEnum) String() string {
|
||||||
return utils.Str[d]
|
return tools.Str[d]
|
||||||
}
|
}
|
||||||
|
|
||||||
// will turn into enum index
|
// will turn into enum index
|
||||||
@ -65,6 +68,20 @@ func (d LibDataEnum) EnumIndex() int {
|
|||||||
return int(d)
|
return int(d)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func IsQueryParamsEquals(input *context.BeegoInput, name string, val interface{}) bool {
|
||||||
|
path := strings.Split(input.URI(), "?")
|
||||||
|
if len(path) >= 2 {
|
||||||
|
uri := strings.Split(path[1], "&")
|
||||||
|
for _, val := range uri {
|
||||||
|
kv := strings.Split(val, "=")
|
||||||
|
if kv[0] == name && fmt.Sprintf("%v", val) == kv[1] {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
// model to define the shallow data structure
|
// model to define the shallow data structure
|
||||||
type LibDataShallow struct {
|
type LibDataShallow struct {
|
||||||
Data []utils.ShallowDBObject `bson:"data" json:"data"`
|
Data []utils.ShallowDBObject `bson:"data" json:"data"`
|
||||||
@ -79,29 +96,32 @@ type LibData struct {
|
|||||||
Err string `bson:"error" json:"error"`
|
Err string `bson:"error" json:"error"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// here is the singleton variable to store the paths that api will use
|
func InitDaemon(appName string) {
|
||||||
var paths map[LibDataEnum]string = map[LibDataEnum]string{}
|
|
||||||
|
|
||||||
// to get the paths
|
|
||||||
func GetPaths() map[LibDataEnum]string {
|
|
||||||
return paths
|
|
||||||
}
|
|
||||||
|
|
||||||
// to get the path
|
|
||||||
func GetPath(collection LibDataEnum) string {
|
|
||||||
return paths[collection]
|
|
||||||
}
|
|
||||||
|
|
||||||
// to add the path
|
|
||||||
func AddPath(collection LibDataEnum, path string) {
|
|
||||||
paths[collection] = path
|
|
||||||
}
|
|
||||||
|
|
||||||
func Init(appName string) {
|
|
||||||
config.SetAppName(appName) // set the app name to the logger to define the main log chan
|
config.SetAppName(appName) // set the app name to the logger to define the main log chan
|
||||||
// create a temporary console logger for init
|
// create a temporary console logger for init
|
||||||
logs.SetLogger(logs.CreateLogger("main"))
|
logs.SetLogger(logs.CreateLogger("main"))
|
||||||
|
// Load the right config file
|
||||||
|
o := GetConfLoader()
|
||||||
|
|
||||||
|
// feed the library with the loaded config
|
||||||
|
SetConfig(
|
||||||
|
o.GetStringDefault("MONGO_URL", "mongodb://127.0.0.1:27017"),
|
||||||
|
o.GetStringDefault("MONGO_DATABASE", "DC_myDC"),
|
||||||
|
o.GetStringDefault("NATS_URL", "nats://localhost:4222"),
|
||||||
|
o.GetStringDefault("LOKI_URL", ""),
|
||||||
|
o.GetStringDefault("LOG_LEVEL", "info"),
|
||||||
|
)
|
||||||
|
// Beego init
|
||||||
|
beego.BConfig.AppName = appName
|
||||||
|
beego.BConfig.Listen.HTTPPort = o.GetIntDefault("port", 8080)
|
||||||
|
beego.BConfig.WebConfig.DirectoryIndex = true
|
||||||
|
beego.BConfig.WebConfig.StaticDir["/swagger"] = "swagger"
|
||||||
|
}
|
||||||
|
|
||||||
|
func Init(appName string) {
|
||||||
|
InitDaemon(appName)
|
||||||
|
api := &tools.API{}
|
||||||
|
api.Discovered(beego.BeeApp.Handlers.GetAllControllerInfo())
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@ -139,17 +159,17 @@ func SetConfig(mongoUrl string, database string, natsUrl string, lokiUrl string,
|
|||||||
Resource model is the model that will define the structure of the resources
|
Resource model is the model that will define the structure of the resources
|
||||||
*/
|
*/
|
||||||
accessor := (&resource_model.ResourceModel{}).GetAccessor(nil)
|
accessor := (&resource_model.ResourceModel{}).GetAccessor(nil)
|
||||||
for _, model := range []string{utils.DATA_RESOURCE.String(), utils.PROCESSING_RESOURCE.String(), utils.STORAGE_RESOURCE.String(), utils.DATACENTER_RESOURCE.String(), utils.WORKFLOW_RESOURCE.String()} {
|
for _, model := range []string{tools.DATA_RESOURCE.String(), tools.PROCESSING_RESOURCE.String(), tools.STORAGE_RESOURCE.String(), tools.COMPUTE_RESOURCE.String(), tools.WORKFLOW_RESOURCE.String()} {
|
||||||
data, code, _ := accessor.Search(nil, model)
|
data, code, _ := accessor.Search(nil, model)
|
||||||
if code == 404 || len(data) == 0 {
|
if code == 404 || len(data) == 0 {
|
||||||
|
refs := map[string]string{}
|
||||||
m := map[string]resource_model.Model{}
|
m := map[string]resource_model.Model{}
|
||||||
// TODO Specify the model for each resource
|
// TODO Specify the model for each resource
|
||||||
// for now only processing is specified here (not an elegant way)
|
// for now only processing is specified here (not an elegant way)
|
||||||
if model == utils.PROCESSING_RESOURCE.String() {
|
if model == tools.DATA_RESOURCE.String() || model == tools.STORAGE_RESOURCE.String() {
|
||||||
m["image"] = resource_model.Model{
|
refs["path"] = "string"
|
||||||
Type: "string",
|
|
||||||
ReadOnly: false,
|
|
||||||
}
|
}
|
||||||
|
if model == tools.PROCESSING_RESOURCE.String() {
|
||||||
m["command"] = resource_model.Model{
|
m["command"] = resource_model.Model{
|
||||||
Type: "string",
|
Type: "string",
|
||||||
ReadOnly: false,
|
ReadOnly: false,
|
||||||
@ -158,14 +178,21 @@ func SetConfig(mongoUrl string, database string, natsUrl string, lokiUrl string,
|
|||||||
Type: "string",
|
Type: "string",
|
||||||
ReadOnly: false,
|
ReadOnly: false,
|
||||||
}
|
}
|
||||||
m["execute"] = resource_model.Model{
|
m["env"] = resource_model.Model{
|
||||||
Type: "map[int]map[string]string",
|
Type: "string",
|
||||||
|
ReadOnly: false,
|
||||||
|
}
|
||||||
|
m["volumes"] = resource_model.Model{
|
||||||
|
Type: "map[string]string",
|
||||||
ReadOnly: false,
|
ReadOnly: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
accessor.StoreOne(&resource_model.ResourceModel{
|
accessor.StoreOne(&resource_model.ResourceModel{
|
||||||
ResourceType: model,
|
ResourceType: model,
|
||||||
Model: m,
|
VarRefs: refs,
|
||||||
|
Model: map[string]map[string]resource_model.Model{
|
||||||
|
"container": m,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -394,72 +421,72 @@ func CopyOne(collection LibDataEnum, object map[string]interface{}, c ...*tools.
|
|||||||
// ================ CAST ========================= //
|
// ================ CAST ========================= //
|
||||||
|
|
||||||
func (l *LibData) ToDataResource() *data.DataResource {
|
func (l *LibData) ToDataResource() *data.DataResource {
|
||||||
if l.Data.GetAccessor(nil).GetType() == utils.DATA_RESOURCE.String() {
|
if l.Data.GetAccessor(nil).GetType() == tools.DATA_RESOURCE.String() {
|
||||||
return l.Data.(*data.DataResource)
|
return l.Data.(*data.DataResource)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *LibData) ToDatacenterResource() *datacenter.DatacenterResource {
|
func (l *LibData) ToComputeResource() *compute.ComputeResource {
|
||||||
if l.Data != nil && l.Data.GetAccessor(nil).GetType() == utils.DATACENTER_RESOURCE.String() {
|
if l.Data != nil && l.Data.GetAccessor(nil).GetType() == tools.COMPUTE_RESOURCE.String() {
|
||||||
return l.Data.(*datacenter.DatacenterResource)
|
return l.Data.(*compute.ComputeResource)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
func (l *LibData) ToStorageResource() *storage.StorageResource {
|
func (l *LibData) ToStorageResource() *storage.StorageResource {
|
||||||
if l.Data.GetAccessor(nil).GetType() == utils.STORAGE_RESOURCE.String() {
|
if l.Data.GetAccessor(nil).GetType() == tools.STORAGE_RESOURCE.String() {
|
||||||
return l.Data.(*storage.StorageResource)
|
return l.Data.(*storage.StorageResource)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
func (l *LibData) ToProcessingResource() *processing.ProcessingResource {
|
func (l *LibData) ToProcessingResource() *processing.ProcessingResource {
|
||||||
if l.Data.GetAccessor(nil).GetType() == utils.PROCESSING_RESOURCE.String() {
|
if l.Data.GetAccessor(nil).GetType() == tools.PROCESSING_RESOURCE.String() {
|
||||||
return l.Data.(*processing.ProcessingResource)
|
return l.Data.(*processing.ProcessingResource)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
func (l *LibData) ToWorkflowResource() *w.WorkflowResource {
|
func (l *LibData) ToWorkflowResource() *w.WorkflowResource {
|
||||||
if l.Data.GetAccessor(nil).GetType() == utils.WORKFLOW_RESOURCE.String() {
|
if l.Data.GetAccessor(nil).GetType() == tools.WORKFLOW_RESOURCE.String() {
|
||||||
return l.Data.(*w.WorkflowResource)
|
return l.Data.(*w.WorkflowResource)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
func (l *LibData) ToPeer() *peer.Peer {
|
func (l *LibData) ToPeer() *peer.Peer {
|
||||||
if l.Data.GetAccessor(nil).GetType() == utils.PEER.String() {
|
if l.Data.GetAccessor(nil).GetType() == tools.PEER.String() {
|
||||||
return l.Data.(*peer.Peer)
|
return l.Data.(*peer.Peer)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *LibData) ToWorkflow() *w2.Workflow {
|
func (l *LibData) ToWorkflow() *w2.Workflow {
|
||||||
if l.Data.GetAccessor(nil).GetType() == utils.WORKFLOW.String() {
|
if l.Data.GetAccessor(nil).GetType() == tools.WORKFLOW.String() {
|
||||||
return l.Data.(*w2.Workflow)
|
return l.Data.(*w2.Workflow)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
func (l *LibData) ToWorkspace() *workspace.Workspace {
|
func (l *LibData) ToWorkspace() *workspace.Workspace {
|
||||||
if l.Data.GetAccessor(nil).GetType() == utils.WORKSPACE.String() {
|
if l.Data.GetAccessor(nil).GetType() == tools.WORKSPACE.String() {
|
||||||
return l.Data.(*workspace.Workspace)
|
return l.Data.(*workspace.Workspace)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *LibData) ToSharedWorkspace() *shared_workspace.SharedWorkspace {
|
func (l *LibData) ToCollaborativeArea() *collaborative_area.CollaborativeArea {
|
||||||
if l.Data.GetAccessor(nil).GetType() == utils.SHARED_WORKSPACE.String() {
|
if l.Data.GetAccessor(nil).GetType() == tools.COLLABORATIVE_AREA.String() {
|
||||||
return l.Data.(*shared_workspace.SharedWorkspace)
|
return l.Data.(*collaborative_area.CollaborativeArea)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *LibData) ToRule() *rule.Rule {
|
func (l *LibData) ToRule() *rule.Rule {
|
||||||
if l.Data.GetAccessor(nil).GetType() == utils.SHARED_WORKSPACE.String() {
|
if l.Data.GetAccessor(nil).GetType() == tools.COLLABORATIVE_AREA.String() {
|
||||||
return l.Data.(*rule.Rule)
|
return l.Data.(*rule.Rule)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *LibData) ToWorkflowExecution() *workflow_execution.WorkflowExecution {
|
func (l *LibData) ToWorkflowExecution() *workflow_execution.WorkflowExecution {
|
||||||
if l.Data.GetAccessor(nil).GetType() == utils.WORKFLOW_EXECUTION.String() {
|
if l.Data.GetAccessor(nil).GetType() == tools.WORKFLOW_EXECUTION.String() {
|
||||||
return l.Data.(*workflow_execution.WorkflowExecution)
|
return l.Data.(*workflow_execution.WorkflowExecution)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
14
go.mod
14
go.mod
@ -3,6 +3,7 @@ module cloud.o-forge.io/core/oc-lib
|
|||||||
go 1.22.0
|
go 1.22.0
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
github.com/beego/beego/v2 v2.3.1
|
||||||
github.com/go-playground/validator/v10 v10.22.0
|
github.com/go-playground/validator/v10 v10.22.0
|
||||||
github.com/google/uuid v1.6.0
|
github.com/google/uuid v1.6.0
|
||||||
github.com/goraz/onion v0.1.3
|
github.com/goraz/onion v0.1.3
|
||||||
@ -25,16 +26,25 @@ require (
|
|||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
github.com/beorn7/perks v1.0.1 // indirect
|
||||||
|
github.com/cespare/xxhash/v2 v2.2.0 // indirect
|
||||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||||
github.com/gabriel-vasile/mimetype v1.4.4 // indirect
|
github.com/gabriel-vasile/mimetype v1.4.4 // indirect
|
||||||
github.com/go-playground/locales v0.14.1 // indirect
|
github.com/go-playground/locales v0.14.1 // indirect
|
||||||
github.com/go-playground/universal-translator v0.18.1 // indirect
|
github.com/go-playground/universal-translator v0.18.1 // indirect
|
||||||
github.com/golang/snappy v0.0.4 // indirect
|
github.com/golang/snappy v0.0.4 // indirect
|
||||||
|
github.com/hashicorp/golang-lru v0.5.4 // indirect
|
||||||
github.com/klauspost/compress v1.17.9 // indirect
|
github.com/klauspost/compress v1.17.9 // indirect
|
||||||
|
github.com/kr/text v0.1.0 // indirect
|
||||||
github.com/leodido/go-urn v1.4.0 // indirect
|
github.com/leodido/go-urn v1.4.0 // indirect
|
||||||
|
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
||||||
github.com/montanaflynn/stats v0.7.1 // indirect
|
github.com/montanaflynn/stats v0.7.1 // indirect
|
||||||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
|
|
||||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||||
|
github.com/prometheus/client_golang v1.19.0 // indirect
|
||||||
|
github.com/prometheus/client_model v0.5.0 // indirect
|
||||||
|
github.com/prometheus/common v0.48.0 // indirect
|
||||||
|
github.com/prometheus/procfs v0.12.0 // indirect
|
||||||
|
github.com/shiena/ansicolor v0.0.0-20200904210342-c7312218db18 // indirect
|
||||||
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
|
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
|
||||||
github.com/xdg-go/scram v1.1.2 // indirect
|
github.com/xdg-go/scram v1.1.2 // indirect
|
||||||
github.com/xdg-go/stringprep v1.0.4 // indirect
|
github.com/xdg-go/stringprep v1.0.4 // indirect
|
||||||
@ -43,6 +53,6 @@ require (
|
|||||||
golang.org/x/net v0.27.0 // indirect
|
golang.org/x/net v0.27.0 // indirect
|
||||||
golang.org/x/sync v0.7.0 // indirect
|
golang.org/x/sync v0.7.0 // indirect
|
||||||
golang.org/x/text v0.16.0 // indirect
|
golang.org/x/text v0.16.0 // indirect
|
||||||
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
|
google.golang.org/protobuf v1.34.2 // indirect
|
||||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
)
|
)
|
||||||
|
34
go.sum
34
go.sum
@ -1,10 +1,18 @@
|
|||||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||||
|
github.com/beego/beego/v2 v2.3.1 h1:7MUKMpJYzOXtCUsTEoXOxsDV/UcHw6CPbaWMlthVNsc=
|
||||||
|
github.com/beego/beego/v2 v2.3.1/go.mod h1:5cqHsOHJIxkq44tBpRvtDe59GuVRVv/9/tyVDxd5ce4=
|
||||||
|
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
|
||||||
|
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
|
||||||
|
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
|
||||||
|
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
||||||
github.com/coreos/etcd v3.3.17+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
|
github.com/coreos/etcd v3.3.17+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
|
||||||
github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
|
github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
|
||||||
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
|
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
|
||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/elazarl/go-bindata-assetfs v1.0.1 h1:m0kkaHRKEu7tUIUFVwhGGGYClXvyl4RE03qmvRTNfbw=
|
||||||
|
github.com/elazarl/go-bindata-assetfs v1.0.1/go.mod h1:v+YaWX3bdea5J/mo8dSETolEo7R71Vk1u8bnjau5yw4=
|
||||||
github.com/etcd-io/etcd v3.3.17+incompatible/go.mod h1:cdZ77EstHBwVtD6iTgzgvogwcjo9m4iOqoijouPJ4bs=
|
github.com/etcd-io/etcd v3.3.17+incompatible/go.mod h1:cdZ77EstHBwVtD6iTgzgvogwcjo9m4iOqoijouPJ4bs=
|
||||||
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
|
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
|
||||||
github.com/gabriel-vasile/mimetype v1.4.4 h1:QjV6pZ7/XZ7ryI2KuyeEDE8wnh7fHP9YnQy+R0LnH8I=
|
github.com/gabriel-vasile/mimetype v1.4.4 h1:QjV6pZ7/XZ7ryI2KuyeEDE8wnh7fHP9YnQy+R0LnH8I=
|
||||||
@ -29,12 +37,16 @@ github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGa
|
|||||||
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
|
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
|
||||||
github.com/goraz/onion v0.1.3 h1:KhyvbDA2b70gcz/d5izfwTiOH8SmrvV43AsVzpng3n0=
|
github.com/goraz/onion v0.1.3 h1:KhyvbDA2b70gcz/d5izfwTiOH8SmrvV43AsVzpng3n0=
|
||||||
github.com/goraz/onion v0.1.3/go.mod h1:XEmz1XoBz+wxTgWB8NwuvRm4RAu3vKxvrmYtzK+XCuQ=
|
github.com/goraz/onion v0.1.3/go.mod h1:XEmz1XoBz+wxTgWB8NwuvRm4RAu3vKxvrmYtzK+XCuQ=
|
||||||
|
github.com/hashicorp/golang-lru v0.5.4 h1:YDjusn29QI/Das2iO9M0BHnIbxPeyuCHsjMW+lJfyTc=
|
||||||
|
github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4=
|
||||||
github.com/imdario/mergo v0.3.8/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
|
github.com/imdario/mergo v0.3.8/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
|
||||||
github.com/json-iterator/go v1.1.8/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
|
github.com/json-iterator/go v1.1.8/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
|
||||||
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
|
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
|
||||||
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
|
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
|
||||||
github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA=
|
github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA=
|
||||||
github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
|
github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
|
||||||
|
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
||||||
|
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
|
||||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||||
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
|
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
|
||||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||||
@ -48,6 +60,8 @@ github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D
|
|||||||
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
||||||
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||||
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
|
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
|
||||||
|
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
|
||||||
|
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
|
||||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||||
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
|
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
|
||||||
@ -60,18 +74,28 @@ github.com/nats-io/nkeys v0.4.7 h1:RwNJbbIdYCoClSDNY7QVKZlyb/wfT6ugvFCiKy6vDvI=
|
|||||||
github.com/nats-io/nkeys v0.4.7/go.mod h1:kqXRgRDPlGy7nGaEDMuYzmiJCIAAWDK0IMBtDmGD0nc=
|
github.com/nats-io/nkeys v0.4.7/go.mod h1:kqXRgRDPlGy7nGaEDMuYzmiJCIAAWDK0IMBtDmGD0nc=
|
||||||
github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw=
|
github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw=
|
||||||
github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c=
|
github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c=
|
||||||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
|
|
||||||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
|
|
||||||
github.com/ogier/pflag v0.0.1/go.mod h1:zkFki7tvTa0tafRvTBIZTvzYyAu6kQhPZFnshFFPE+g=
|
github.com/ogier/pflag v0.0.1/go.mod h1:zkFki7tvTa0tafRvTBIZTvzYyAu6kQhPZFnshFFPE+g=
|
||||||
github.com/pelletier/go-toml v1.6.0/go.mod h1:5N711Q9dKgbdkxHL+MEfF31hpT7l0S0s/t2kKREewys=
|
github.com/pelletier/go-toml v1.6.0/go.mod h1:5N711Q9dKgbdkxHL+MEfF31hpT7l0S0s/t2kKREewys=
|
||||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
|
github.com/prometheus/client_golang v1.19.0 h1:ygXvpU1AoN1MhdzckN+PyD9QJOSD4x7kmXYlnfbA6JU=
|
||||||
|
github.com/prometheus/client_golang v1.19.0/go.mod h1:ZRM9uEAypZakd+q/x7+gmsvXdURP+DABIEIjnmDdp+k=
|
||||||
|
github.com/prometheus/client_model v0.5.0 h1:VQw1hfvPvk3Uv6Qf29VrPF32JB6rtbgI6cYPYQjL0Qw=
|
||||||
|
github.com/prometheus/client_model v0.5.0/go.mod h1:dTiFglRmd66nLR9Pv9f0mZi7B7fk5Pm3gvsjB5tr+kI=
|
||||||
|
github.com/prometheus/common v0.48.0 h1:QO8U2CdOzSn1BBsmXJXduaaW+dY/5QLjfB8svtSzKKE=
|
||||||
|
github.com/prometheus/common v0.48.0/go.mod h1:0/KsvlIEfPQCQ5I2iNSAWKPZziNCvRs5EC6ILDTlAPc=
|
||||||
|
github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k6Bo=
|
||||||
|
github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo=
|
||||||
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
|
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
|
||||||
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
|
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
|
||||||
|
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
|
||||||
|
github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog=
|
||||||
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
|
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
|
||||||
github.com/rs/zerolog v1.33.0 h1:1cU2KZkvPxNyfgEmhHAz/1A9Bz+llsdYzklWFzgp0r8=
|
github.com/rs/zerolog v1.33.0 h1:1cU2KZkvPxNyfgEmhHAz/1A9Bz+llsdYzklWFzgp0r8=
|
||||||
github.com/rs/zerolog v1.33.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss=
|
github.com/rs/zerolog v1.33.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss=
|
||||||
|
github.com/shiena/ansicolor v0.0.0-20200904210342-c7312218db18 h1:DAYUYH5869yV94zvCES9F51oYtN5oGlwjxJJz7ZCnik=
|
||||||
|
github.com/shiena/ansicolor v0.0.0-20200904210342-c7312218db18/go.mod h1:nkxAfR/5quYxwPZhyDxgasBMnRtBZd0FCEpawpjMUFg=
|
||||||
github.com/skarademir/naturalsort v0.0.0-20150715044055-69a5d87bef62/go.mod h1:oIdVclZaltY1Nf7OQUkg1/2jImBJ+ZfKZuDIRSwk3p0=
|
github.com/skarademir/naturalsort v0.0.0-20150715044055-69a5d87bef62/go.mod h1:oIdVclZaltY1Nf7OQUkg1/2jImBJ+ZfKZuDIRSwk3p0=
|
||||||
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
|
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
|
||||||
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
|
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
|
||||||
@ -134,9 +158,11 @@ golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3
|
|||||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||||
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
||||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
|
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
|
||||||
|
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=
|
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
||||||
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
||||||
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
|
@ -17,10 +17,10 @@ import (
|
|||||||
*/
|
*/
|
||||||
type Booking struct {
|
type Booking struct {
|
||||||
workflow_execution.WorkflowExecution // WorkflowExecution contains the workflow execution data
|
workflow_execution.WorkflowExecution // WorkflowExecution contains the workflow execution data
|
||||||
DatacenterResourceID string `json:"datacenter_resource_id,omitempty" bson:"datacenter_resource_id,omitempty" validate:"required"` // DatacenterResourceID is the ID of the datacenter resource specified in the booking
|
ComputeResourceID string `json:"compute_resource_id,omitempty" bson:"compute_resource_id,omitempty" validate:"required"` // ComputeResourceID is the ID of the compute resource specified in the booking
|
||||||
}
|
}
|
||||||
|
|
||||||
// CheckBooking checks if a booking is possible on a specific datacenter resource
|
// CheckBooking checks if a booking is possible on a specific compute resource
|
||||||
func (wfa *Booking) CheckBooking(id string, start time.Time, end *time.Time) (bool, error) {
|
func (wfa *Booking) CheckBooking(id string, start time.Time, end *time.Time) (bool, error) {
|
||||||
// check if
|
// check if
|
||||||
if end == nil {
|
if end == nil {
|
||||||
@ -30,8 +30,8 @@ func (wfa *Booking) CheckBooking(id string, start time.Time, end *time.Time) (bo
|
|||||||
e := *end
|
e := *end
|
||||||
accessor := wfa.GetAccessor(nil)
|
accessor := wfa.GetAccessor(nil)
|
||||||
res, code, err := accessor.Search(&dbs.Filters{
|
res, code, err := accessor.Search(&dbs.Filters{
|
||||||
And: map[string][]dbs.Filter{ // check if there is a booking on the same datacenter resource by filtering on the datacenter_resource_id, the state and the execution date
|
And: map[string][]dbs.Filter{ // check if there is a booking on the same compute resource by filtering on the compute_resource_id, the state and the execution date
|
||||||
"datacenter_resource_id": {{Operator: dbs.EQUAL.String(), Value: id}},
|
"compute_resource_id": {{Operator: dbs.EQUAL.String(), Value: id}},
|
||||||
"workflowexecution.state": {{Operator: dbs.EQUAL.String(), Value: workflow_execution.SCHEDULED.EnumIndex()}},
|
"workflowexecution.state": {{Operator: dbs.EQUAL.String(), Value: workflow_execution.SCHEDULED.EnumIndex()}},
|
||||||
"workflowexecution.execution_date": {
|
"workflowexecution.execution_date": {
|
||||||
{Operator: dbs.LTE.String(), Value: primitive.NewDateTimeFromTime(e)},
|
{Operator: dbs.LTE.String(), Value: primitive.NewDateTimeFromTime(e)},
|
||||||
@ -65,7 +65,7 @@ func (d *Booking) GetName() string {
|
|||||||
|
|
||||||
func (d *Booking) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
|
func (d *Booking) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
|
||||||
data := New() // Create a new instance of the accessor
|
data := New() // Create a new instance of the accessor
|
||||||
data.Init(utils.BOOKING, caller) // Initialize the accessor with the BOOKING model type
|
data.Init(tools.BOOKING, caller) // Initialize the accessor with the BOOKING model type
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
package shared_workspace
|
package collaborative_area
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
|
||||||
|
"cloud.o-forge.io/core/oc-lib/models/collaborative_area/rules/rule"
|
||||||
"cloud.o-forge.io/core/oc-lib/models/peer"
|
"cloud.o-forge.io/core/oc-lib/models/peer"
|
||||||
"cloud.o-forge.io/core/oc-lib/models/utils"
|
"cloud.o-forge.io/core/oc-lib/models/utils"
|
||||||
w "cloud.o-forge.io/core/oc-lib/models/workflow"
|
w "cloud.o-forge.io/core/oc-lib/models/workflow"
|
||||||
"cloud.o-forge.io/core/oc-lib/models/workspace"
|
"cloud.o-forge.io/core/oc-lib/models/workspace"
|
||||||
"cloud.o-forge.io/core/oc-lib/models/workspace/shared/rules/rule"
|
|
||||||
"cloud.o-forge.io/core/oc-lib/tools"
|
"cloud.o-forge.io/core/oc-lib/tools"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
)
|
)
|
||||||
@ -16,7 +16,7 @@ import (
|
|||||||
// WARNING : it got a shallow object version, this one is the full version
|
// WARNING : it got a shallow object version, this one is the full version
|
||||||
// full version is the one used by API
|
// full version is the one used by API
|
||||||
// other one is a shallow version used by the Lib for import cycle problem purposes
|
// other one is a shallow version used by the Lib for import cycle problem purposes
|
||||||
type SharedWorkspace struct {
|
type CollaborativeArea struct {
|
||||||
utils.AbstractObject // AbstractObject contains the basic fields of an object (id, name)
|
utils.AbstractObject // AbstractObject contains the basic fields of an object (id, name)
|
||||||
IsSent bool `json:"is_sent" bson:"-"` // IsSent is a flag that indicates if the workspace is sent
|
IsSent bool `json:"is_sent" bson:"-"` // IsSent is a flag that indicates if the workspace is sent
|
||||||
CreatorID string `json:"peer_id,omitempty" bson:"peer_id,omitempty" validate:"required"` // CreatorID is the ID of the creator
|
CreatorID string `json:"peer_id,omitempty" bson:"peer_id,omitempty" validate:"required"` // CreatorID is the ID of the creator
|
||||||
@ -34,27 +34,27 @@ type SharedWorkspace struct {
|
|||||||
SharedPeers []*peer.Peer `json:"shared_peers,omitempty" bson:"-"` // SharedPeers is the shared peers of the workspace
|
SharedPeers []*peer.Peer `json:"shared_peers,omitempty" bson:"-"` // SharedPeers is the shared peers of the workspace
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ao *SharedWorkspace) GetID() string {
|
func (ao *CollaborativeArea) GetID() string {
|
||||||
return ao.UUID
|
return ao.UUID
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *SharedWorkspace) GenerateID() {
|
func (r *CollaborativeArea) GenerateID() {
|
||||||
if r.UUID == "" {
|
if r.UUID == "" {
|
||||||
r.UUID = uuid.New().String()
|
r.UUID = uuid.New().String()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *SharedWorkspace) GetName() string {
|
func (d *CollaborativeArea) GetName() string {
|
||||||
return d.Name
|
return d.Name
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *SharedWorkspace) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
|
func (d *CollaborativeArea) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
|
||||||
data := New() // Create a new instance of the accessor
|
data := New() // Create a new instance of the accessor
|
||||||
data.Init(utils.SHARED_WORKSPACE, caller) // Initialize the accessor with the SHARED_WORKSPACE model type
|
data.Init(tools.COLLABORATIVE_AREA, caller) // Initialize the accessor with the SHARED_WORKSPACE model type
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dma *SharedWorkspace) Deserialize(j map[string]interface{}) utils.DBObject {
|
func (dma *CollaborativeArea) Deserialize(j map[string]interface{}) utils.DBObject {
|
||||||
b, err := json.Marshal(j)
|
b, err := json.Marshal(j)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
return nil
|
||||||
@ -63,7 +63,7 @@ func (dma *SharedWorkspace) Deserialize(j map[string]interface{}) utils.DBObject
|
|||||||
return dma
|
return dma
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dma *SharedWorkspace) Serialize() map[string]interface{} {
|
func (dma *CollaborativeArea) Serialize() map[string]interface{} {
|
||||||
var m map[string]interface{}
|
var m map[string]interface{}
|
||||||
b, err := json.Marshal(dma)
|
b, err := json.Marshal(dma)
|
||||||
if err != nil {
|
if err != nil {
|
@ -1,4 +1,4 @@
|
|||||||
package shared_workspace
|
package collaborative_area
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
@ -6,53 +6,52 @@ import (
|
|||||||
|
|
||||||
"cloud.o-forge.io/core/oc-lib/dbs"
|
"cloud.o-forge.io/core/oc-lib/dbs"
|
||||||
"cloud.o-forge.io/core/oc-lib/dbs/mongo"
|
"cloud.o-forge.io/core/oc-lib/dbs/mongo"
|
||||||
|
"cloud.o-forge.io/core/oc-lib/models/collaborative_area/rules/rule"
|
||||||
"cloud.o-forge.io/core/oc-lib/models/peer"
|
"cloud.o-forge.io/core/oc-lib/models/peer"
|
||||||
"cloud.o-forge.io/core/oc-lib/models/utils"
|
"cloud.o-forge.io/core/oc-lib/models/utils"
|
||||||
w "cloud.o-forge.io/core/oc-lib/models/workflow"
|
w "cloud.o-forge.io/core/oc-lib/models/workflow"
|
||||||
"cloud.o-forge.io/core/oc-lib/models/workspace"
|
"cloud.o-forge.io/core/oc-lib/models/workspace"
|
||||||
"cloud.o-forge.io/core/oc-lib/models/workspace/shared/rules/rule"
|
|
||||||
"cloud.o-forge.io/core/oc-lib/static"
|
|
||||||
"cloud.o-forge.io/core/oc-lib/tools"
|
"cloud.o-forge.io/core/oc-lib/tools"
|
||||||
)
|
)
|
||||||
|
|
||||||
// SharedWorkspace is a struct that represents a shared workspace
|
// SharedWorkspace is a struct that represents a collaborative area
|
||||||
type sharedWorkspaceMongoAccessor struct {
|
type collaborativeAreaMongoAccessor struct {
|
||||||
utils.AbstractAccessor // AbstractAccessor contains the basic fields of an accessor (model, caller)
|
utils.AbstractAccessor // AbstractAccessor contains the basic fields of an accessor (model, caller)
|
||||||
}
|
}
|
||||||
|
|
||||||
// New creates a new instance of the sharedWorkspaceMongoAccessor
|
// New creates a new instance of the collaborativeAreaMongoAccessor
|
||||||
func New() *sharedWorkspaceMongoAccessor {
|
func New() *collaborativeAreaMongoAccessor {
|
||||||
return &sharedWorkspaceMongoAccessor{}
|
return &collaborativeAreaMongoAccessor{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteOne deletes a shared workspace from the database, given its ID, it automatically share to peers if the workspace is shared
|
// DeleteOne deletes a collaborative area from the database, given its ID, it automatically share to peers if the workspace is shared
|
||||||
func (wfa *sharedWorkspaceMongoAccessor) DeleteOne(id string) (utils.DBObject, int, error) {
|
func (wfa *collaborativeAreaMongoAccessor) DeleteOne(id string) (utils.DBObject, int, error) {
|
||||||
set, code, _ := wfa.LoadOne(id)
|
set, code, _ := wfa.LoadOne(id)
|
||||||
if code == 200 { // always delete on peers than recreate
|
if code == 200 { // always delete on peers than recreate
|
||||||
wfa.deleteToPeer(set.(*SharedWorkspace))
|
wfa.deleteToPeer(set.(*CollaborativeArea))
|
||||||
}
|
}
|
||||||
wfa.sharedWorkflow(&SharedWorkspace{}, id) // create all shared workflows
|
wfa.sharedWorkflow(&CollaborativeArea{}, id) // create all shared workflows
|
||||||
wfa.sharedWorkspace(&SharedWorkspace{}, id) // create all shared workspaces
|
wfa.sharedWorkspace(&CollaborativeArea{}, id) // create all collaborative areas
|
||||||
return wfa.GenericDeleteOne(id, wfa) // then add on yours
|
return wfa.GenericDeleteOne(id, wfa) // then add on yours
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
sharedWorkspace is a function that shares the shared workspace to the peers
|
sharedWorkspace is a function that shares the collaborative area to the peers
|
||||||
*/
|
*/
|
||||||
func (wfa *sharedWorkspaceMongoAccessor) sharedWorkspace(shared *SharedWorkspace, id string) {
|
func (wfa *collaborativeAreaMongoAccessor) sharedWorkspace(shared *CollaborativeArea, id string) {
|
||||||
eldest, code, _ := wfa.LoadOne(id) // get the eldest
|
eldest, code, _ := wfa.LoadOne(id) // get the eldest
|
||||||
accessor := (&workspace.Workspace{}).GetAccessor(nil)
|
accessor := (&workspace.Workspace{}).GetAccessor(nil)
|
||||||
if code == 200 {
|
if code == 200 {
|
||||||
eld := eldest.(*SharedWorkspace)
|
eld := eldest.(*CollaborativeArea)
|
||||||
if eld.Workspaces != nil { // update all your workspaces in the eldest by replacing shared ref by an empty string
|
if eld.Workspaces != nil { // update all your workspaces in the eldest by replacing shared ref by an empty string
|
||||||
for _, v := range eld.Workspaces {
|
for _, v := range eld.Workspaces {
|
||||||
accessor.UpdateOne(&workspace.Workspace{Shared: ""}, v)
|
accessor.UpdateOne(&workspace.Workspace{Shared: ""}, v)
|
||||||
if wfa.Caller != nil || wfa.Caller.URLS == nil || wfa.Caller.URLS[utils.WORKSPACE.String()] == nil {
|
if wfa.Caller != nil || wfa.Caller.URLS == nil || wfa.Caller.URLS[tools.WORKSPACE] == nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
paccess := (&peer.Peer{}) // send to all peers
|
paccess := (&peer.Peer{}) // send to all peers
|
||||||
for _, p := range shared.Peers { // delete the shared workspace on the peer
|
for _, p := range shared.Peers { // delete the collaborative area on the peer
|
||||||
b, err := paccess.LaunchPeerExecution(p, v, utils.WORKSPACE, tools.DELETE, nil, wfa.Caller)
|
b, err := paccess.LaunchPeerExecution(p, v, tools.WORKSPACE, tools.DELETE, nil, wfa.Caller)
|
||||||
if err != nil && b == nil {
|
if err != nil && b == nil {
|
||||||
wfa.Logger.Error().Msg("Could not send to peer " + p + ". Error: " + err.Error())
|
wfa.Logger.Error().Msg("Could not send to peer " + p + ". Error: " + err.Error())
|
||||||
}
|
}
|
||||||
@ -61,19 +60,19 @@ func (wfa *sharedWorkspaceMongoAccessor) sharedWorkspace(shared *SharedWorkspace
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if shared.Workspaces != nil {
|
if shared.Workspaces != nil {
|
||||||
for _, v := range shared.Workspaces { // update all the shared workspaces
|
for _, v := range shared.Workspaces { // update all the collaborative areas
|
||||||
workspace, code, _ := accessor.UpdateOne(&workspace.Workspace{Shared: shared.UUID}, v) // add the shared ref to workspace
|
workspace, code, _ := accessor.UpdateOne(&workspace.Workspace{Shared: shared.UUID}, v) // add the shared ref to workspace
|
||||||
if wfa.Caller != nil || wfa.Caller.URLS == nil || wfa.Caller.URLS[utils.WORKSPACE.String()] == nil {
|
if wfa.Caller != nil || wfa.Caller.URLS == nil || wfa.Caller.URLS[tools.WORKSPACE] == nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
for _, p := range shared.Peers {
|
for _, p := range shared.Peers {
|
||||||
if code != 200 {
|
if code != 200 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
paccess := (&peer.Peer{}) // send to all peers, add the shared workspace on the peer
|
paccess := (&peer.Peer{}) // send to all peers, add the collaborative area on the peer
|
||||||
s := workspace.Serialize()
|
s := workspace.Serialize()
|
||||||
s["name"] = fmt.Sprintf("%v", s["name"]) + "_" + p
|
s["name"] = fmt.Sprintf("%v", s["name"]) + "_" + p
|
||||||
b, err := paccess.LaunchPeerExecution(p, v, utils.WORKSPACE, tools.POST, s, wfa.Caller)
|
b, err := paccess.LaunchPeerExecution(p, v, tools.WORKSPACE, tools.POST, s, wfa.Caller)
|
||||||
if err != nil && b == nil {
|
if err != nil && b == nil {
|
||||||
wfa.Logger.Error().Msg("Could not send to peer " + p + ". Error: " + err.Error())
|
wfa.Logger.Error().Msg("Could not send to peer " + p + ". Error: " + err.Error())
|
||||||
}
|
}
|
||||||
@ -81,15 +80,15 @@ func (wfa *sharedWorkspaceMongoAccessor) sharedWorkspace(shared *SharedWorkspace
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// deleting on peers before adding, to avoid conflicts on peers side
|
// deleting on peers before adding, to avoid conflicts on peers side
|
||||||
// because you have no reference to the remote shared workspace
|
// because you have no reference to the remote collaborative area
|
||||||
}
|
}
|
||||||
|
|
||||||
// sharedWorkflow is a function that shares the shared workflow to the peers
|
// sharedWorkflow is a function that shares the shared workflow to the peers
|
||||||
func (wfa *sharedWorkspaceMongoAccessor) sharedWorkflow(shared *SharedWorkspace, id string) {
|
func (wfa *collaborativeAreaMongoAccessor) sharedWorkflow(shared *CollaborativeArea, id string) {
|
||||||
accessor := (&w.Workflow{}).GetAccessor(nil)
|
accessor := (&w.Workflow{}).GetAccessor(nil)
|
||||||
eldest, code, _ := wfa.LoadOne(id) // get the eldest
|
eldest, code, _ := wfa.LoadOne(id) // get the eldest
|
||||||
if code == 200 {
|
if code == 200 {
|
||||||
eld := eldest.(*SharedWorkspace)
|
eld := eldest.(*CollaborativeArea)
|
||||||
if eld.Workflows != nil {
|
if eld.Workflows != nil {
|
||||||
for _, v := range eld.Workflows {
|
for _, v := range eld.Workflows {
|
||||||
data, code, _ := accessor.LoadOne(v)
|
data, code, _ := accessor.LoadOne(v)
|
||||||
@ -104,12 +103,12 @@ func (wfa *sharedWorkspaceMongoAccessor) sharedWorkflow(shared *SharedWorkspace,
|
|||||||
n := &w.Workflow{}
|
n := &w.Workflow{}
|
||||||
n.Shared = new
|
n.Shared = new
|
||||||
accessor.UpdateOne(n, v)
|
accessor.UpdateOne(n, v)
|
||||||
if wfa.Caller != nil || wfa.Caller.URLS == nil || wfa.Caller.URLS[utils.WORKFLOW.String()] == nil {
|
if wfa.Caller != nil || wfa.Caller.URLS == nil || wfa.Caller.URLS[tools.WORKFLOW] == nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
paccess := (&peer.Peer{}) // send to all peers
|
paccess := (&peer.Peer{}) // send to all peers
|
||||||
for _, p := range shared.Peers { // delete the shared workflow on the peer
|
for _, p := range shared.Peers { // delete the shared workflow on the peer
|
||||||
b, err := paccess.LaunchPeerExecution(p, v, utils.WORKFLOW, tools.DELETE, nil, wfa.Caller)
|
b, err := paccess.LaunchPeerExecution(p, v, tools.WORKFLOW, tools.DELETE, nil, wfa.Caller)
|
||||||
if err != nil && b == nil {
|
if err != nil && b == nil {
|
||||||
wfa.Logger.Error().Msg("Could not send to peer " + p + ". Error: " + err.Error())
|
wfa.Logger.Error().Msg("Could not send to peer " + p + ". Error: " + err.Error())
|
||||||
}
|
}
|
||||||
@ -126,7 +125,7 @@ func (wfa *sharedWorkspaceMongoAccessor) sharedWorkflow(shared *SharedWorkspace,
|
|||||||
if !slices.Contains(s.Shared, id) {
|
if !slices.Contains(s.Shared, id) {
|
||||||
s.Shared = append(s.Shared, id)
|
s.Shared = append(s.Shared, id)
|
||||||
workflow, code, _ := accessor.UpdateOne(s, v)
|
workflow, code, _ := accessor.UpdateOne(s, v)
|
||||||
if wfa.Caller != nil || wfa.Caller.URLS == nil || wfa.Caller.URLS[utils.WORKFLOW.String()] == nil {
|
if wfa.Caller != nil || wfa.Caller.URLS == nil || wfa.Caller.URLS[tools.WORKFLOW] == nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
paccess := (&peer.Peer{})
|
paccess := (&peer.Peer{})
|
||||||
@ -134,7 +133,7 @@ func (wfa *sharedWorkspaceMongoAccessor) sharedWorkflow(shared *SharedWorkspace,
|
|||||||
if code == 200 {
|
if code == 200 {
|
||||||
s := workflow.Serialize() // add the shared workflow on the peer
|
s := workflow.Serialize() // add the shared workflow on the peer
|
||||||
s["name"] = fmt.Sprintf("%v", s["name"]) + "_" + p
|
s["name"] = fmt.Sprintf("%v", s["name"]) + "_" + p
|
||||||
b, err := paccess.LaunchPeerExecution(p, shared.UUID, utils.WORKFLOW, tools.POST, s, wfa.Caller)
|
b, err := paccess.LaunchPeerExecution(p, shared.UUID, tools.WORKFLOW, tools.POST, s, wfa.Caller)
|
||||||
if err != nil && b == nil {
|
if err != nil && b == nil {
|
||||||
wfa.Logger.Error().Msg("Could not send to peer " + p + ". Error: " + err.Error())
|
wfa.Logger.Error().Msg("Could not send to peer " + p + ". Error: " + err.Error())
|
||||||
}
|
}
|
||||||
@ -148,85 +147,85 @@ func (wfa *sharedWorkspaceMongoAccessor) sharedWorkflow(shared *SharedWorkspace,
|
|||||||
// because you have no reference to the remote shared workflow
|
// because you have no reference to the remote shared workflow
|
||||||
}
|
}
|
||||||
|
|
||||||
// sharedWorkspace is a function that shares the shared workspace to the peers
|
// sharedWorkspace is a function that shares the collaborative area to the peers
|
||||||
func (wfa *sharedWorkspaceMongoAccessor) deleteToPeer(shared *SharedWorkspace) {
|
func (wfa *collaborativeAreaMongoAccessor) deleteToPeer(shared *CollaborativeArea) {
|
||||||
if wfa.Caller == nil || wfa.Caller.URLS == nil || wfa.Caller.URLS[utils.SHARED_WORKSPACE.String()] == nil {
|
if wfa.Caller == nil || wfa.Caller.URLS == nil || wfa.Caller.URLS[tools.COLLABORATIVE_AREA] == nil || wfa.Caller.Disabled {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
paccess := (&peer.Peer{})
|
paccess := (&peer.Peer{})
|
||||||
for _, v := range shared.Peers {
|
for _, v := range shared.Peers {
|
||||||
if (&peer.Peer{AbstractObject: utils.AbstractObject{UUID: v}}).IsMySelf() {
|
if ok, _ := (&peer.Peer{AbstractObject: utils.AbstractObject{UUID: v}}).IsMySelf(); ok {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
b, err := paccess.LaunchPeerExecution(v, shared.UUID, utils.SHARED_WORKSPACE, tools.DELETE, nil, wfa.Caller)
|
b, err := paccess.LaunchPeerExecution(v, shared.UUID, tools.COLLABORATIVE_AREA, tools.DELETE, nil, wfa.Caller)
|
||||||
if err != nil && b == nil {
|
if err != nil && b == nil {
|
||||||
wfa.Logger.Error().Msg("Could not send to peer " + v + ". Error: " + err.Error())
|
wfa.Logger.Error().Msg("Could not send to peer " + v + ". Error: " + err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// sharedWorkspace is a function that shares the shared workspace to the peers
|
// sharedWorkspace is a function that shares the collaborative area to the peers
|
||||||
func (wfa *sharedWorkspaceMongoAccessor) sendToPeer(shared *SharedWorkspace) {
|
func (wfa *collaborativeAreaMongoAccessor) sendToPeer(shared *CollaborativeArea) {
|
||||||
if wfa.Caller == nil || wfa.Caller.URLS == nil || wfa.Caller.URLS[utils.SHARED_WORKSPACE.String()] == nil {
|
if wfa.Caller == nil || wfa.Caller.URLS == nil || wfa.Caller.URLS[tools.COLLABORATIVE_AREA] == nil || wfa.Caller.Disabled {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
paccess := (&peer.Peer{})
|
paccess := (&peer.Peer{})
|
||||||
for _, v := range shared.Peers {
|
for _, v := range shared.Peers {
|
||||||
if (&peer.Peer{AbstractObject: utils.AbstractObject{UUID: v}}).IsMySelf() || shared.IsSent {
|
if ok, _ := (&peer.Peer{AbstractObject: utils.AbstractObject{UUID: v}}).IsMySelf(); ok || shared.IsSent {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
shared.IsSent = true
|
shared.IsSent = true
|
||||||
b, err := paccess.LaunchPeerExecution(v, v, utils.SHARED_WORKSPACE, tools.POST, shared.Serialize(), wfa.Caller)
|
b, err := paccess.LaunchPeerExecution(v, v, tools.COLLABORATIVE_AREA, tools.POST, shared.Serialize(), wfa.Caller)
|
||||||
if err != nil && b == nil {
|
if err != nil && b == nil {
|
||||||
wfa.Logger.Error().Msg("Could not send to peer " + v + ". Error: " + err.Error())
|
wfa.Logger.Error().Msg("Could not send to peer " + v + ". Error: " + err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateOne updates a shared workspace in the database, given its ID and the new data, it automatically share to peers if the workspace is shared
|
// UpdateOne updates a collaborative area in the database, given its ID and the new data, it automatically share to peers if the workspace is shared
|
||||||
func (wfa *sharedWorkspaceMongoAccessor) UpdateOne(set utils.DBObject, id string) (utils.DBObject, int, error) {
|
func (wfa *collaborativeAreaMongoAccessor) UpdateOne(set utils.DBObject, id string) (utils.DBObject, int, error) {
|
||||||
res, code, err := wfa.GenericUpdateOne(set.(*SharedWorkspace), id, wfa, &SharedWorkspace{})
|
res, code, err := wfa.GenericUpdateOne(set.(*CollaborativeArea), id, wfa, &CollaborativeArea{})
|
||||||
wfa.deleteToPeer(res.(*SharedWorkspace)) // delete the shared workspace on the peer
|
wfa.deleteToPeer(res.(*CollaborativeArea)) // delete the collaborative area on the peer
|
||||||
wfa.sharedWorkflow(res.(*SharedWorkspace), id) // replace all shared workflows
|
wfa.sharedWorkflow(res.(*CollaborativeArea), id) // replace all shared workflows
|
||||||
wfa.sharedWorkspace(res.(*SharedWorkspace), id) // replace all shared workspaces (not shared worspace obj but workspace one)
|
wfa.sharedWorkspace(res.(*CollaborativeArea), id) // replace all collaborative areas (not shared worspace obj but workspace one)
|
||||||
wfa.sendToPeer(res.(*SharedWorkspace)) // send the shared workspace (shared workspace object) to the peers
|
wfa.sendToPeer(res.(*CollaborativeArea)) // send the collaborative area (collaborative area object) to the peers
|
||||||
return res, code, err
|
return res, code, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// StoreOne stores a shared workspace in the database, it automatically share to peers if the workspace is shared
|
// StoreOne stores a collaborative area in the database, it automatically share to peers if the workspace is shared
|
||||||
func (wfa *sharedWorkspaceMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject, int, error) {
|
func (wfa *collaborativeAreaMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject, int, error) {
|
||||||
id, _ := static.GetMyLocalJsonPeer() // get the local peer
|
_, id := (&peer.Peer{}).IsMySelf() // get the local peer
|
||||||
data.(*SharedWorkspace).CreatorID = id // set the creator id
|
data.(*CollaborativeArea).CreatorID = id // set the creator id
|
||||||
data.(*SharedWorkspace).Peers = append(data.(*SharedWorkspace).Peers, id) // add the creator id to the peers
|
data.(*CollaborativeArea).Peers = append(data.(*CollaborativeArea).Peers, id) // add the creator id to the peers
|
||||||
// then reset the shared fields
|
// then reset the shared fields
|
||||||
if data.(*SharedWorkspace).Workspaces == nil {
|
if data.(*CollaborativeArea).Workspaces == nil {
|
||||||
data.(*SharedWorkspace).Workspaces = []string{}
|
data.(*CollaborativeArea).Workspaces = []string{}
|
||||||
}
|
}
|
||||||
if data.(*SharedWorkspace).Workflows == nil {
|
if data.(*CollaborativeArea).Workflows == nil {
|
||||||
data.(*SharedWorkspace).Workflows = []string{}
|
data.(*CollaborativeArea).Workflows = []string{}
|
||||||
}
|
}
|
||||||
if data.(*SharedWorkspace).Rules == nil {
|
if data.(*CollaborativeArea).Rules == nil {
|
||||||
data.(*SharedWorkspace).Rules = []string{}
|
data.(*CollaborativeArea).Rules = []string{}
|
||||||
}
|
}
|
||||||
|
|
||||||
d, code, err := wfa.GenericStoreOne(data.(*SharedWorkspace), wfa)
|
d, code, err := wfa.GenericStoreOne(data.(*CollaborativeArea), wfa)
|
||||||
|
|
||||||
if code == 200 {
|
if code == 200 {
|
||||||
wfa.sharedWorkflow(d.(*SharedWorkspace), d.GetID()) // create all shared workflows
|
wfa.sharedWorkflow(d.(*CollaborativeArea), d.GetID()) // create all shared workflows
|
||||||
wfa.sharedWorkspace(d.(*SharedWorkspace), d.GetID()) // create all shared workspaces
|
wfa.sharedWorkspace(d.(*CollaborativeArea), d.GetID()) // create all collaborative areas
|
||||||
wfa.sendToPeer(d.(*SharedWorkspace)) // send the shared workspace (shared workspace object) to the peers
|
wfa.sendToPeer(d.(*CollaborativeArea)) // send the collaborative area (collaborative area object) to the peers
|
||||||
}
|
}
|
||||||
return data, code, err
|
return data, code, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// CopyOne copies a shared workspace in the database
|
// CopyOne copies a CollaborativeArea in the database
|
||||||
func (wfa *sharedWorkspaceMongoAccessor) CopyOne(data utils.DBObject) (utils.DBObject, int, error) {
|
func (wfa *collaborativeAreaMongoAccessor) CopyOne(data utils.DBObject) (utils.DBObject, int, error) {
|
||||||
return wfa.StoreOne(data)
|
return wfa.StoreOne(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
// enrich is a function that enriches the shared workspace with the shared objects
|
// enrich is a function that enriches the CollaborativeArea with the shared objects
|
||||||
func (wfa *sharedWorkspaceMongoAccessor) enrich(sharedWorkspace *SharedWorkspace) *SharedWorkspace {
|
func (wfa *collaborativeAreaMongoAccessor) enrich(sharedWorkspace *CollaborativeArea) *CollaborativeArea {
|
||||||
access := (&workspace.Workspace{}).GetAccessor(nil)
|
access := (&workspace.Workspace{}).GetAccessor(nil)
|
||||||
res, code, _ := access.Search(&dbs.Filters{
|
res, code, _ := access.Search(&dbs.Filters{
|
||||||
Or: map[string][]dbs.Filter{
|
Or: map[string][]dbs.Filter{
|
||||||
@ -274,38 +273,38 @@ func (wfa *sharedWorkspaceMongoAccessor) enrich(sharedWorkspace *SharedWorkspace
|
|||||||
return sharedWorkspace
|
return sharedWorkspace
|
||||||
}
|
}
|
||||||
|
|
||||||
// LoadOne loads a shared workspace from the database, given its ID and enrich it
|
// LoadOne loads a collaborative area from the database, given its ID and enrich it
|
||||||
func (wfa *sharedWorkspaceMongoAccessor) LoadOne(id string) (utils.DBObject, int, error) {
|
func (wfa *collaborativeAreaMongoAccessor) LoadOne(id string) (utils.DBObject, int, error) {
|
||||||
var sharedWorkspace SharedWorkspace
|
var sharedWorkspace CollaborativeArea
|
||||||
res_mongo, code, err := mongo.MONGOService.LoadOne(id, wfa.GetType())
|
res_mongo, code, err := mongo.MONGOService.LoadOne(id, wfa.GetType())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
wfa.Logger.Error().Msg("Could not retrieve " + id + " from db. Error: " + err.Error())
|
wfa.Logger.Error().Msg("Could not retrieve " + id + " from db. Error: " + err.Error())
|
||||||
return nil, code, err
|
return nil, code, err
|
||||||
}
|
}
|
||||||
res_mongo.Decode(&sharedWorkspace)
|
res_mongo.Decode(&sharedWorkspace)
|
||||||
return wfa.enrich(&sharedWorkspace), 200, nil // enrich the shared workspace
|
return wfa.enrich(&sharedWorkspace), 200, nil // enrich the collaborative area
|
||||||
}
|
}
|
||||||
|
|
||||||
// LoadAll loads all the shared workspaces from the database and enrich them
|
// LoadAll loads all the collaborative areas from the database and enrich them
|
||||||
func (wfa sharedWorkspaceMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int, error) {
|
func (wfa collaborativeAreaMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int, error) {
|
||||||
objs := []utils.ShallowDBObject{}
|
objs := []utils.ShallowDBObject{}
|
||||||
res_mongo, code, err := mongo.MONGOService.LoadAll(wfa.GetType())
|
res_mongo, code, err := mongo.MONGOService.LoadAll(wfa.GetType())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
wfa.Logger.Error().Msg("Could not retrieve any from db. Error: " + err.Error())
|
wfa.Logger.Error().Msg("Could not retrieve any from db. Error: " + err.Error())
|
||||||
return nil, code, err
|
return nil, code, err
|
||||||
}
|
}
|
||||||
var results []SharedWorkspace
|
var results []CollaborativeArea
|
||||||
if err = res_mongo.All(mongo.MngoCtx, &results); err != nil {
|
if err = res_mongo.All(mongo.MngoCtx, &results); err != nil {
|
||||||
return nil, 404, err
|
return nil, 404, err
|
||||||
}
|
}
|
||||||
for _, r := range results {
|
for _, r := range results {
|
||||||
objs = append(objs, wfa.enrich(&r)) // enrich the shared workspace
|
objs = append(objs, wfa.enrich(&r)) // enrich the collaborative area
|
||||||
}
|
}
|
||||||
return objs, 200, nil
|
return objs, 200, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Search searches for shared workspaces in the database, given some filters OR a search string
|
// Search searches for collaborative areas in the database, given some filters OR a search string
|
||||||
func (wfa *sharedWorkspaceMongoAccessor) Search(filters *dbs.Filters, search string) ([]utils.ShallowDBObject, int, error) {
|
func (wfa *collaborativeAreaMongoAccessor) Search(filters *dbs.Filters, search string) ([]utils.ShallowDBObject, int, error) {
|
||||||
objs := []utils.ShallowDBObject{}
|
objs := []utils.ShallowDBObject{}
|
||||||
if (filters == nil || len(filters.And) == 0 || len(filters.Or) == 0) && search != "" {
|
if (filters == nil || len(filters.And) == 0 || len(filters.Or) == 0) && search != "" {
|
||||||
filters = &dbs.Filters{
|
filters = &dbs.Filters{
|
||||||
@ -319,12 +318,12 @@ func (wfa *sharedWorkspaceMongoAccessor) Search(filters *dbs.Filters, search str
|
|||||||
wfa.Logger.Error().Msg("Could not store to db. Error: " + err.Error())
|
wfa.Logger.Error().Msg("Could not store to db. Error: " + err.Error())
|
||||||
return nil, code, err
|
return nil, code, err
|
||||||
}
|
}
|
||||||
var results []SharedWorkspace
|
var results []CollaborativeArea
|
||||||
if err = res_mongo.All(mongo.MngoCtx, &results); err != nil {
|
if err = res_mongo.All(mongo.MngoCtx, &results); err != nil {
|
||||||
return nil, 404, err
|
return nil, 404, err
|
||||||
}
|
}
|
||||||
for _, r := range results {
|
for _, r := range results {
|
||||||
objs = append(objs, wfa.enrich(&r)) // enrich the shared workspace
|
objs = append(objs, wfa.enrich(&r)) // enrich the collaborative area
|
||||||
}
|
}
|
||||||
return objs, 200, nil
|
return objs, 200, nil
|
||||||
}
|
}
|
@ -32,7 +32,7 @@ func (d *Rule) GetName() string {
|
|||||||
|
|
||||||
func (d *Rule) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
|
func (d *Rule) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
|
||||||
data := New()
|
data := New()
|
||||||
data.Init(utils.RULE, caller)
|
data.Init(tools.RULE, caller)
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package shallow_shared_workspace
|
package shallow_collaborative_area
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
@ -8,7 +8,7 @@ import (
|
|||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ShallowSharedWorkspace struct {
|
type ShallowCollaborativeArea struct {
|
||||||
utils.AbstractObject
|
utils.AbstractObject
|
||||||
IsSent bool `json:"is_sent" bson:"-"`
|
IsSent bool `json:"is_sent" bson:"-"`
|
||||||
CreatorID string `json:"peer_id,omitempty" bson:"peer_id,omitempty" validate:"required"`
|
CreatorID string `json:"peer_id,omitempty" bson:"peer_id,omitempty" validate:"required"`
|
||||||
@ -21,27 +21,27 @@ type ShallowSharedWorkspace struct {
|
|||||||
Rules []string `json:"rules,omitempty" bson:"rules,omitempty"`
|
Rules []string `json:"rules,omitempty" bson:"rules,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ao *ShallowSharedWorkspace) GetID() string {
|
func (ao *ShallowCollaborativeArea) GetID() string {
|
||||||
return ao.UUID
|
return ao.UUID
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *ShallowSharedWorkspace) GenerateID() {
|
func (r *ShallowCollaborativeArea) GenerateID() {
|
||||||
if r.UUID == "" {
|
if r.UUID == "" {
|
||||||
r.UUID = uuid.New().String()
|
r.UUID = uuid.New().String()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *ShallowSharedWorkspace) GetName() string {
|
func (d *ShallowCollaborativeArea) GetName() string {
|
||||||
return d.Name
|
return d.Name
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *ShallowSharedWorkspace) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
|
func (d *ShallowCollaborativeArea) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
|
||||||
data := New()
|
data := New()
|
||||||
data.Init(utils.SHARED_WORKSPACE, caller)
|
data.Init(tools.COLLABORATIVE_AREA, caller)
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dma *ShallowSharedWorkspace) Deserialize(j map[string]interface{}) utils.DBObject {
|
func (dma *ShallowCollaborativeArea) Deserialize(j map[string]interface{}) utils.DBObject {
|
||||||
b, err := json.Marshal(j)
|
b, err := json.Marshal(j)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
return nil
|
||||||
@ -50,7 +50,7 @@ func (dma *ShallowSharedWorkspace) Deserialize(j map[string]interface{}) utils.D
|
|||||||
return dma
|
return dma
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dma *ShallowSharedWorkspace) Serialize() map[string]interface{} {
|
func (dma *ShallowCollaborativeArea) Serialize() map[string]interface{} {
|
||||||
var m map[string]interface{}
|
var m map[string]interface{}
|
||||||
b, err := json.Marshal(dma)
|
b, err := json.Marshal(dma)
|
||||||
if err != nil {
|
if err != nil {
|
@ -1,4 +1,4 @@
|
|||||||
package shallow_shared_workspace
|
package shallow_collaborative_area
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"cloud.o-forge.io/core/oc-lib/dbs"
|
"cloud.o-forge.io/core/oc-lib/dbs"
|
||||||
@ -19,11 +19,11 @@ func (wfa *shallowSharedWorkspaceMongoAccessor) DeleteOne(id string) (utils.DBOb
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (wfa *shallowSharedWorkspaceMongoAccessor) UpdateOne(set utils.DBObject, id string) (utils.DBObject, int, error) {
|
func (wfa *shallowSharedWorkspaceMongoAccessor) UpdateOne(set utils.DBObject, id string) (utils.DBObject, int, error) {
|
||||||
return wfa.GenericUpdateOne(set.(*ShallowSharedWorkspace), id, wfa, &ShallowSharedWorkspace{})
|
return wfa.GenericUpdateOne(set.(*ShallowCollaborativeArea), id, wfa, &ShallowCollaborativeArea{})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (wfa *shallowSharedWorkspaceMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject, int, error) {
|
func (wfa *shallowSharedWorkspaceMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject, int, error) {
|
||||||
return wfa.GenericStoreOne(data.(*ShallowSharedWorkspace), wfa)
|
return wfa.GenericStoreOne(data.(*ShallowCollaborativeArea), wfa)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (wfa *shallowSharedWorkspaceMongoAccessor) CopyOne(data utils.DBObject) (utils.DBObject, int, error) {
|
func (wfa *shallowSharedWorkspaceMongoAccessor) CopyOne(data utils.DBObject) (utils.DBObject, int, error) {
|
||||||
@ -31,7 +31,7 @@ func (wfa *shallowSharedWorkspaceMongoAccessor) CopyOne(data utils.DBObject) (ut
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (wfa *shallowSharedWorkspaceMongoAccessor) LoadOne(id string) (utils.DBObject, int, error) {
|
func (wfa *shallowSharedWorkspaceMongoAccessor) LoadOne(id string) (utils.DBObject, int, error) {
|
||||||
var sharedWorkspace ShallowSharedWorkspace
|
var sharedWorkspace ShallowCollaborativeArea
|
||||||
res_mongo, code, err := mongo.MONGOService.LoadOne(id, wfa.GetType())
|
res_mongo, code, err := mongo.MONGOService.LoadOne(id, wfa.GetType())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
wfa.Logger.Error().Msg("Could not retrieve " + id + " from db. Error: " + err.Error())
|
wfa.Logger.Error().Msg("Could not retrieve " + id + " from db. Error: " + err.Error())
|
||||||
@ -48,7 +48,7 @@ func (wfa shallowSharedWorkspaceMongoAccessor) LoadAll() ([]utils.ShallowDBObjec
|
|||||||
wfa.Logger.Error().Msg("Could not retrieve any from db. Error: " + err.Error())
|
wfa.Logger.Error().Msg("Could not retrieve any from db. Error: " + err.Error())
|
||||||
return nil, code, err
|
return nil, code, err
|
||||||
}
|
}
|
||||||
var results []ShallowSharedWorkspace
|
var results []ShallowCollaborativeArea
|
||||||
if err = res_mongo.All(mongo.MngoCtx, &results); err != nil {
|
if err = res_mongo.All(mongo.MngoCtx, &results); err != nil {
|
||||||
return nil, 404, err
|
return nil, 404, err
|
||||||
}
|
}
|
||||||
@ -72,7 +72,7 @@ func (wfa *shallowSharedWorkspaceMongoAccessor) Search(filters *dbs.Filters, sea
|
|||||||
wfa.Logger.Error().Msg("Could not store to db. Error: " + err.Error())
|
wfa.Logger.Error().Msg("Could not store to db. Error: " + err.Error())
|
||||||
return nil, code, err
|
return nil, code, err
|
||||||
}
|
}
|
||||||
var results []ShallowSharedWorkspace
|
var results []ShallowCollaborativeArea
|
||||||
if err = res_mongo.All(mongo.MngoCtx, &results); err != nil {
|
if err = res_mongo.All(mongo.MngoCtx, &results); err != nil {
|
||||||
return nil, 404, err
|
return nil, 404, err
|
||||||
}
|
}
|
@ -2,12 +2,15 @@ package models
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"cloud.o-forge.io/core/oc-lib/logs"
|
"cloud.o-forge.io/core/oc-lib/logs"
|
||||||
|
"cloud.o-forge.io/core/oc-lib/tools"
|
||||||
|
|
||||||
"cloud.o-forge.io/core/oc-lib/models/booking"
|
"cloud.o-forge.io/core/oc-lib/models/booking"
|
||||||
|
"cloud.o-forge.io/core/oc-lib/models/collaborative_area"
|
||||||
|
"cloud.o-forge.io/core/oc-lib/models/collaborative_area/rules/rule"
|
||||||
"cloud.o-forge.io/core/oc-lib/models/peer"
|
"cloud.o-forge.io/core/oc-lib/models/peer"
|
||||||
"cloud.o-forge.io/core/oc-lib/models/resource_model"
|
"cloud.o-forge.io/core/oc-lib/models/resource_model"
|
||||||
d "cloud.o-forge.io/core/oc-lib/models/resources/data"
|
d "cloud.o-forge.io/core/oc-lib/models/resources/data"
|
||||||
dc "cloud.o-forge.io/core/oc-lib/models/resources/datacenter"
|
"cloud.o-forge.io/core/oc-lib/models/resources/compute"
|
||||||
p "cloud.o-forge.io/core/oc-lib/models/resources/processing"
|
p "cloud.o-forge.io/core/oc-lib/models/resources/processing"
|
||||||
s "cloud.o-forge.io/core/oc-lib/models/resources/storage"
|
s "cloud.o-forge.io/core/oc-lib/models/resources/storage"
|
||||||
w "cloud.o-forge.io/core/oc-lib/models/resources/workflow"
|
w "cloud.o-forge.io/core/oc-lib/models/resources/workflow"
|
||||||
@ -15,8 +18,6 @@ import (
|
|||||||
w2 "cloud.o-forge.io/core/oc-lib/models/workflow"
|
w2 "cloud.o-forge.io/core/oc-lib/models/workflow"
|
||||||
"cloud.o-forge.io/core/oc-lib/models/workflow_execution"
|
"cloud.o-forge.io/core/oc-lib/models/workflow_execution"
|
||||||
w3 "cloud.o-forge.io/core/oc-lib/models/workspace"
|
w3 "cloud.o-forge.io/core/oc-lib/models/workspace"
|
||||||
shared_workspace "cloud.o-forge.io/core/oc-lib/models/workspace/shared"
|
|
||||||
"cloud.o-forge.io/core/oc-lib/models/workspace/shared/rules/rule"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -24,28 +25,30 @@ This package contains the models used in the application
|
|||||||
It's used to create the models dynamically
|
It's used to create the models dynamically
|
||||||
*/
|
*/
|
||||||
var models = map[string]func() utils.DBObject{
|
var models = map[string]func() utils.DBObject{
|
||||||
utils.WORKFLOW_RESOURCE.String(): func() utils.DBObject { return &w.WorkflowResource{} },
|
tools.WORKFLOW_RESOURCE.String(): func() utils.DBObject { return &w.WorkflowResource{} },
|
||||||
utils.DATA_RESOURCE.String(): func() utils.DBObject { return &d.DataResource{} },
|
tools.DATA_RESOURCE.String(): func() utils.DBObject { return &d.DataResource{} },
|
||||||
utils.DATACENTER_RESOURCE.String(): func() utils.DBObject { return &dc.DatacenterResource{} },
|
tools.COMPUTE_RESOURCE.String(): func() utils.DBObject { return &compute.ComputeResource{} },
|
||||||
utils.STORAGE_RESOURCE.String(): func() utils.DBObject { return &s.StorageResource{} },
|
tools.STORAGE_RESOURCE.String(): func() utils.DBObject { return &s.StorageResource{} },
|
||||||
utils.PROCESSING_RESOURCE.String(): func() utils.DBObject { return &p.ProcessingResource{} },
|
tools.PROCESSING_RESOURCE.String(): func() utils.DBObject { return &p.ProcessingResource{} },
|
||||||
utils.WORKFLOW.String(): func() utils.DBObject { return &w2.Workflow{} },
|
tools.WORKFLOW.String(): func() utils.DBObject { return &w2.Workflow{} },
|
||||||
utils.WORKFLOW_EXECUTION.String(): func() utils.DBObject { return &workflow_execution.WorkflowExecution{} },
|
tools.WORKFLOW_EXECUTION.String(): func() utils.DBObject { return &workflow_execution.WorkflowExecution{} },
|
||||||
utils.WORKSPACE.String(): func() utils.DBObject { return &w3.Workspace{} },
|
tools.WORKSPACE.String(): func() utils.DBObject { return &w3.Workspace{} },
|
||||||
utils.RESOURCE_MODEL.String(): func() utils.DBObject { return &resource_model.ResourceModel{} },
|
tools.RESOURCE_MODEL.String(): func() utils.DBObject { return &resource_model.ResourceModel{} },
|
||||||
utils.PEER.String(): func() utils.DBObject { return &peer.Peer{} },
|
tools.PEER.String(): func() utils.DBObject { return &peer.Peer{} },
|
||||||
utils.SHARED_WORKSPACE.String(): func() utils.DBObject { return &shared_workspace.SharedWorkspace{} },
|
tools.COLLABORATIVE_AREA.String(): func() utils.DBObject { return &collaborative_area.CollaborativeArea{} },
|
||||||
utils.RULE.String(): func() utils.DBObject { return &rule.Rule{} },
|
tools.RULE.String(): func() utils.DBObject { return &rule.Rule{} },
|
||||||
utils.BOOKING.String(): func() utils.DBObject { return &booking.Booking{} },
|
tools.BOOKING.String(): func() utils.DBObject { return &booking.Booking{} },
|
||||||
|
tools.WORKFLOW_HISTORY.String(): func() utils.DBObject { return &w2.WorkflowHistory{} },
|
||||||
|
tools.WORKSPACE_HISTORY.String(): func() utils.DBObject { return &w3.WorkspaceHistory{} },
|
||||||
}
|
}
|
||||||
|
|
||||||
// Model returns the model object based on the model type
|
// Model returns the model object based on the model type
|
||||||
func Model(model int) utils.DBObject {
|
func Model(model int) utils.DBObject {
|
||||||
log := logs.GetLogger()
|
log := logs.GetLogger()
|
||||||
if _, ok := models[utils.FromInt(model)]; ok {
|
if _, ok := models[tools.FromInt(model)]; ok {
|
||||||
return models[utils.FromInt(model)]()
|
return models[tools.FromInt(model)]()
|
||||||
}
|
}
|
||||||
log.Error().Msg("Can't find model " + utils.FromInt(model) + ".")
|
log.Error().Msg("Can't find model " + tools.FromInt(model) + ".")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,17 +5,36 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"cloud.o-forge.io/core/oc-lib/models/utils"
|
"cloud.o-forge.io/core/oc-lib/models/utils"
|
||||||
"cloud.o-forge.io/core/oc-lib/static"
|
|
||||||
"cloud.o-forge.io/core/oc-lib/tools"
|
"cloud.o-forge.io/core/oc-lib/tools"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// now write a go enum for the state partner with self, blacklist, partner
|
||||||
|
|
||||||
|
type PeerState int
|
||||||
|
|
||||||
|
const (
|
||||||
|
NONE PeerState = iota
|
||||||
|
SELF
|
||||||
|
PARTNER
|
||||||
|
BLACKLIST
|
||||||
|
)
|
||||||
|
|
||||||
|
func (m PeerState) String() string {
|
||||||
|
return [...]string{"NONE", "SELF", "PARTNER", "BLACKLIST"}[m]
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m PeerState) EnumIndex() int {
|
||||||
|
return int(m)
|
||||||
|
}
|
||||||
|
|
||||||
// Peer is a struct that represents a peer
|
// Peer is a struct that represents a peer
|
||||||
type Peer struct {
|
type Peer struct {
|
||||||
utils.AbstractObject
|
utils.AbstractObject
|
||||||
Url string `json:"url,omitempty" bson:"url,omitempty" validate:"required,base64url"` // Url is the URL of the peer (base64url)
|
Url string `json:"url,omitempty" bson:"url,omitempty" validate:"required,base64url"` // Url is the URL of the peer (base64url)
|
||||||
PublicKey string `json:"public_key,omitempty" bson:"public_key,omitempty"` // PublicKey is the public key of the peer
|
PublicKey string `json:"public_key,omitempty" bson:"public_key,omitempty"` // PublicKey is the public key of the peer
|
||||||
Services map[string]int `json:"services,omitempty" bson:"services,omitempty"` // Services is the services of the peer
|
Services map[string]int `json:"services,omitempty" bson:"services,omitempty"`
|
||||||
|
State PeerState `json:"state" bson:"state" default:"0"`
|
||||||
FailedExecution []PeerExecution `json:"failed_execution" bson:"failed_execution"` // FailedExecution is the list of failed executions, to be retried
|
FailedExecution []PeerExecution `json:"failed_execution" bson:"failed_execution"` // FailedExecution is the list of failed executions, to be retried
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,13 +64,17 @@ func (ao *Peer) RemoveExecution(exec PeerExecution) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// IsMySelf checks if the peer is the local peer
|
// IsMySelf checks if the peer is the local peer
|
||||||
func (ao *Peer) IsMySelf() bool {
|
func (ao *Peer) IsMySelf() (bool, string) {
|
||||||
id, _ := static.GetMyLocalJsonPeer()
|
d, code, err := ao.GetAccessor(nil).Search(nil, SELF.String())
|
||||||
return ao.UUID == id
|
if code != 200 || err != nil || len(d) == 0 {
|
||||||
|
return false, ""
|
||||||
|
}
|
||||||
|
id := d[0].GetID()
|
||||||
|
return ao.UUID == id, id
|
||||||
}
|
}
|
||||||
|
|
||||||
// LaunchPeerExecution launches an execution on a peer
|
// LaunchPeerExecution launches an execution on a peer
|
||||||
func (p *Peer) LaunchPeerExecution(peerID string, dataID string, dt utils.DataType, method tools.METHOD, body map[string]interface{}, caller *tools.HTTPCaller) (*PeerExecution, error) {
|
func (p *Peer) LaunchPeerExecution(peerID string, dataID string, dt tools.DataType, method tools.METHOD, body map[string]interface{}, caller *tools.HTTPCaller) (*PeerExecution, error) {
|
||||||
p.UUID = peerID
|
p.UUID = peerID
|
||||||
return cache.LaunchPeerExecution(peerID, dataID, dt, method, body, caller) // Launch the execution on the peer through the cache
|
return cache.LaunchPeerExecution(peerID, dataID, dt, method, body, caller) // Launch the execution on the peer through the cache
|
||||||
}
|
}
|
||||||
@ -61,7 +84,9 @@ func (ao *Peer) GetID() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *Peer) GenerateID() {
|
func (r *Peer) GenerateID() {
|
||||||
|
if r.UUID == "" {
|
||||||
r.UUID = uuid.New().String()
|
r.UUID = uuid.New().String()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Peer) GetName() string {
|
func (d *Peer) GetName() string {
|
||||||
@ -70,7 +95,7 @@ func (d *Peer) GetName() string {
|
|||||||
|
|
||||||
func (d *Peer) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
|
func (d *Peer) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
|
||||||
data := New() // Create a new instance of the accessor
|
data := New() // Create a new instance of the accessor
|
||||||
data.Init(utils.PEER, caller) // Initialize the accessor with the PEER model type
|
data.Init(tools.PEER, caller) // Initialize the accessor with the PEER model type
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,7 +7,6 @@ import (
|
|||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"cloud.o-forge.io/core/oc-lib/models/utils"
|
|
||||||
"cloud.o-forge.io/core/oc-lib/tools"
|
"cloud.o-forge.io/core/oc-lib/tools"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -30,18 +29,26 @@ type PeerCache struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// urlFormat formats the URL of the peer with the data type API function
|
// urlFormat formats the URL of the peer with the data type API function
|
||||||
func (p *PeerCache) urlFormat(url string, dt utils.DataType) string {
|
func (p *PeerCache) urlFormat(url string, dt tools.DataType) string {
|
||||||
// localhost is replaced by the local peer URL
|
// localhost is replaced by the local peer URL
|
||||||
// because localhost must collide on a web request security protocol
|
// because localhost must collide on a web request security protocol
|
||||||
if strings.Contains(url, "localhost") || strings.Contains(url, "127.0.0.1") {
|
localhost := ""
|
||||||
url = strings.ReplaceAll(url, "localhost", dt.API())
|
if strings.Contains(url, "localhost") {
|
||||||
url = strings.ReplaceAll(url, "127.0.0.1", dt.API())
|
localhost = "localhost"
|
||||||
r := regexp.MustCompile("(:[0-9]+)")
|
}
|
||||||
|
if strings.Contains(url, "127.0.0.1") {
|
||||||
|
localhost = "127.0.0.1"
|
||||||
|
}
|
||||||
|
if localhost != "" {
|
||||||
|
r := regexp.MustCompile("(" + localhost + ":[0-9]+)")
|
||||||
t := r.FindString(url)
|
t := r.FindString(url)
|
||||||
if t != "" {
|
if t != "" {
|
||||||
url = strings.Replace(url, t, ":8080", -1)
|
url = strings.Replace(url, t, dt.API()+":8080/oc", -1)
|
||||||
|
} else {
|
||||||
|
url = strings.ReplaceAll(url, localhost, dt.API()+":8080/oc")
|
||||||
}
|
}
|
||||||
r.ReplaceAllString(url, ":8080")
|
} else {
|
||||||
|
url = url + "/" + dt.API()
|
||||||
}
|
}
|
||||||
return url
|
return url
|
||||||
}
|
}
|
||||||
@ -54,7 +61,7 @@ func (p *PeerCache) checkPeerStatus(peerID string, appName string, caller *tools
|
|||||||
if code != 200 { // no peer no party
|
if code != 200 { // no peer no party
|
||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
methods := caller.URLS[utils.PEER.String()] // Get the methods url of the peer
|
methods := caller.URLS[tools.PEER] // Get the methods url of the peer
|
||||||
if methods == nil {
|
if methods == nil {
|
||||||
return res.(*Peer), false
|
return res.(*Peer), false
|
||||||
}
|
}
|
||||||
@ -62,8 +69,10 @@ func (p *PeerCache) checkPeerStatus(peerID string, appName string, caller *tools
|
|||||||
if meth == "" {
|
if meth == "" {
|
||||||
return res.(*Peer), false
|
return res.(*Peer), false
|
||||||
}
|
}
|
||||||
url := p.urlFormat(res.(*Peer).Url+meth, utils.PEER) // Format the URL
|
url := p.urlFormat(res.(*Peer).Url, tools.PEER) + meth // Format the URL
|
||||||
state, services := api.CheckRemotePeer(url) // Check the status of the peer
|
fmt.Println("Checking peer status on", url, "...")
|
||||||
|
state, services := api.CheckRemotePeer(url)
|
||||||
|
fmt.Println("Checking peer status on", url, state, services) // Check the status of the peer
|
||||||
res.(*Peer).Services = services // Update the services states of the peer
|
res.(*Peer).Services = services // Update the services states of the peer
|
||||||
access.UpdateOne(res, peerID) // Update the peer in the db
|
access.UpdateOne(res, peerID) // Update the peer in the db
|
||||||
return res.(*Peer), state != tools.DEAD && services[appName] == 0 // Return the peer and its status
|
return res.(*Peer), state != tools.DEAD && services[appName] == 0 // Return the peer and its status
|
||||||
@ -71,18 +80,16 @@ func (p *PeerCache) checkPeerStatus(peerID string, appName string, caller *tools
|
|||||||
|
|
||||||
// LaunchPeerExecution launches an execution on a peer
|
// LaunchPeerExecution launches an execution on a peer
|
||||||
func (p *PeerCache) LaunchPeerExecution(peerID string, dataID string,
|
func (p *PeerCache) LaunchPeerExecution(peerID string, dataID string,
|
||||||
dt utils.DataType, method tools.METHOD, body map[string]interface{}, caller *tools.HTTPCaller) (*PeerExecution, error) {
|
dt tools.DataType, method tools.METHOD, body map[string]interface{}, caller *tools.HTTPCaller) (*PeerExecution, error) {
|
||||||
methods := caller.URLS[dt.String()] // Get the methods url of the data type
|
fmt.Println("Launching peer execution on", caller.URLS, dt, method)
|
||||||
if _, ok := methods[method]; !ok {
|
methods := caller.URLS[dt] // Get the methods url of the data type
|
||||||
|
if m, ok := methods[method]; !ok || m == "" {
|
||||||
return nil, errors.New("no path found")
|
return nil, errors.New("no path found")
|
||||||
}
|
}
|
||||||
meth := methods[method] // Get the method url to execute
|
meth := methods[method] // Get the method url to execute
|
||||||
if meth == "" {
|
|
||||||
return nil, errors.New("no path found")
|
|
||||||
} else {
|
|
||||||
meth = strings.ReplaceAll(meth, ":id", dataID) // Replace the id in the url in case of a DELETE / UPDATE method (it's a standard naming in OC)
|
meth = strings.ReplaceAll(meth, ":id", dataID) // Replace the id in the url in case of a DELETE / UPDATE method (it's a standard naming in OC)
|
||||||
}
|
|
||||||
url := ""
|
url := ""
|
||||||
|
|
||||||
// Check the status of the peer
|
// Check the status of the peer
|
||||||
if mypeer, ok := p.checkPeerStatus(peerID, dt.API(), caller); !ok {
|
if mypeer, ok := p.checkPeerStatus(peerID, dt.API(), caller); !ok {
|
||||||
// If the peer is not reachable, add the execution to the failed executions list
|
// If the peer is not reachable, add the execution to the failed executions list
|
||||||
@ -106,6 +113,7 @@ func (p *PeerCache) LaunchPeerExecution(peerID string, dataID string,
|
|||||||
go p.exec(v.Url, tools.ToMethod(v.Method), v.Body, caller)
|
go p.exec(v.Url, tools.ToMethod(v.Method), v.Body, caller)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
fmt.Println("URL exec", url)
|
||||||
return nil, p.exec(url, method, body, caller) // Execute the method
|
return nil, p.exec(url, method, body, caller) // Execute the method
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -127,9 +135,8 @@ func (p *PeerCache) exec(url string, method tools.METHOD, body map[string]interf
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if e, ok := m["error"]; ok && e != "<nil>" && e != "" { // Check if there is an error in the response
|
||||||
if e, ok := m["error"]; !ok && e != "" { // Check if there is an error in the response
|
|
||||||
return errors.New(fmt.Sprintf("%v", m["error"]))
|
return errors.New(fmt.Sprintf("%v", m["error"]))
|
||||||
}
|
}
|
||||||
return err
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package peer
|
package peer
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"cloud.o-forge.io/core/oc-lib/dbs"
|
"cloud.o-forge.io/core/oc-lib/dbs"
|
||||||
"cloud.o-forge.io/core/oc-lib/dbs/mongo"
|
"cloud.o-forge.io/core/oc-lib/dbs/mongo"
|
||||||
"cloud.o-forge.io/core/oc-lib/models/utils"
|
"cloud.o-forge.io/core/oc-lib/models/utils"
|
||||||
@ -67,12 +69,22 @@ func (wfa peerMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int, error) {
|
|||||||
func (wfa *peerMongoAccessor) Search(filters *dbs.Filters, search string) ([]utils.ShallowDBObject, int, error) {
|
func (wfa *peerMongoAccessor) Search(filters *dbs.Filters, search string) ([]utils.ShallowDBObject, int, error) {
|
||||||
objs := []utils.ShallowDBObject{}
|
objs := []utils.ShallowDBObject{}
|
||||||
if (filters == nil || len(filters.And) == 0 || len(filters.Or) == 0) && search != "" {
|
if (filters == nil || len(filters.And) == 0 || len(filters.Or) == 0) && search != "" {
|
||||||
|
s, err := strconv.Atoi(search)
|
||||||
|
if err == nil {
|
||||||
|
filters = &dbs.Filters{
|
||||||
|
Or: map[string][]dbs.Filter{ // search by name if no filters are provided
|
||||||
|
"state": {{Operator: dbs.EQUAL.String(), Value: s}},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
} else {
|
||||||
filters = &dbs.Filters{
|
filters = &dbs.Filters{
|
||||||
Or: map[string][]dbs.Filter{ // search by name if no filters are provided
|
Or: map[string][]dbs.Filter{ // search by name if no filters are provided
|
||||||
"abstractobject.name": {{Operator: dbs.LIKE.String(), Value: search}},
|
"abstractobject.name": {{Operator: dbs.LIKE.String(), Value: search}},
|
||||||
|
"url": {{Operator: dbs.LIKE.String(), Value: search}},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
res_mongo, code, err := mongo.MONGOService.Search(filters, wfa.GetType())
|
res_mongo, code, err := mongo.MONGOService.Search(filters, wfa.GetType())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
wfa.Logger.Error().Msg("Could not store to db. Error: " + err.Error())
|
wfa.Logger.Error().Msg("Could not store to db. Error: " + err.Error())
|
||||||
|
@ -8,6 +8,11 @@ import (
|
|||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type WebResource struct {
|
||||||
|
Protocol string `bson:"protocol,omitempty" json:"protocol,omitempty"` // Protocol is the protocol of the URL
|
||||||
|
Path string `bson:"path,omitempty" json:"path,omitempty"` // Path is the path of the URL
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* AbstractResource is a struct that represents a resource
|
* AbstractResource is a struct that represents a resource
|
||||||
* it defines the resource data
|
* it defines the resource data
|
||||||
@ -26,30 +31,17 @@ type AbstractResource struct {
|
|||||||
ResourceModel *ResourceModel `json:"resource_model,omitempty" bson:"resource_model,omitempty"` // ResourceModel is the model of the resource
|
ResourceModel *ResourceModel `json:"resource_model,omitempty" bson:"resource_model,omitempty"` // ResourceModel is the model of the resource
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* GetModelValue returns the value of the model key
|
|
||||||
*/
|
|
||||||
func (abs *AbstractResource) GetModelValue(key string) interface{} {
|
|
||||||
if abs.ResourceModel == nil || abs.ResourceModel.Model == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
if _, ok := abs.ResourceModel.Model[key]; !ok {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return abs.ResourceModel.Model[key].Value
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* GetModelType returns the type of the model key
|
* GetModelType returns the type of the model key
|
||||||
*/
|
*/
|
||||||
func (abs *AbstractResource) GetModelType(key string) interface{} {
|
func (abs *AbstractResource) GetModelType(cat string, key string) interface{} {
|
||||||
if abs.ResourceModel == nil || abs.ResourceModel.Model == nil {
|
if abs.ResourceModel == nil || abs.ResourceModel.Model == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if _, ok := abs.ResourceModel.Model[key]; !ok {
|
if _, ok := abs.ResourceModel.Model[key]; !ok {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return abs.ResourceModel.Model[key].Type
|
return abs.ResourceModel.Model[cat][key].Type
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -66,19 +58,18 @@ func (abs *AbstractResource) GetModelKeys() []string {
|
|||||||
/*
|
/*
|
||||||
* GetModelReadOnly returns the readonly of the model key
|
* GetModelReadOnly returns the readonly of the model key
|
||||||
*/
|
*/
|
||||||
func (abs *AbstractResource) GetModelReadOnly(key string) interface{} {
|
func (abs *AbstractResource) GetModelReadOnly(cat string, key string) interface{} {
|
||||||
if abs.ResourceModel == nil || abs.ResourceModel.Model == nil {
|
if abs.ResourceModel == nil || abs.ResourceModel.Model == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if _, ok := abs.ResourceModel.Model[key]; !ok {
|
if _, ok := abs.ResourceModel.Model[key]; !ok {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return abs.ResourceModel.Model[key].ReadOnly
|
return abs.ResourceModel.Model[cat][key].ReadOnly
|
||||||
}
|
}
|
||||||
|
|
||||||
type Model struct {
|
type Model struct {
|
||||||
Type string `json:"type,omitempty" bson:"type,omitempty"` // Type is the type of the model
|
Type string `json:"type,omitempty" bson:"type,omitempty"` // Type is the type of the model
|
||||||
Value interface{} `json:"value,omitempty" bson:"value,omitempty"` // Value is the value of the model
|
|
||||||
ReadOnly bool `json:"readonly,omitempty" bson:"readonly,omitempty"` // ReadOnly is the readonly of the model
|
ReadOnly bool `json:"readonly,omitempty" bson:"readonly,omitempty"` // ReadOnly is the readonly of the model
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,13 +81,16 @@ type Model struct {
|
|||||||
type ResourceModel struct {
|
type ResourceModel struct {
|
||||||
UUID string `json:"id,omitempty" bson:"id,omitempty" validate:"required"`
|
UUID string `json:"id,omitempty" bson:"id,omitempty" validate:"required"`
|
||||||
ResourceType string `json:"resource_type,omitempty" bson:"resource_type,omitempty" validate:"required"`
|
ResourceType string `json:"resource_type,omitempty" bson:"resource_type,omitempty" validate:"required"`
|
||||||
Model map[string]Model `json:"model,omitempty" bson:"model,omitempty"`
|
VarRefs map[string]string `json:"var_refs,omitempty" bson:"var_refs,omitempty"` // VarRefs is the variable references of the model
|
||||||
|
Model map[string]map[string]Model `json:"model,omitempty" bson:"model,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ao *ResourceModel) GetID() string {
|
func (ao *ResourceModel) GetID() string {
|
||||||
return ao.UUID
|
return ao.UUID
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ao *ResourceModel) UpToDate() {}
|
||||||
|
|
||||||
func (r *ResourceModel) GenerateID() {
|
func (r *ResourceModel) GenerateID() {
|
||||||
r.UUID = uuid.New().String()
|
r.UUID = uuid.New().String()
|
||||||
}
|
}
|
||||||
@ -107,7 +101,7 @@ func (d *ResourceModel) GetName() string {
|
|||||||
|
|
||||||
func (d *ResourceModel) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
|
func (d *ResourceModel) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
|
||||||
data := &ResourceModelMongoAccessor{}
|
data := &ResourceModelMongoAccessor{}
|
||||||
data.Init(utils.RESOURCE_MODEL, caller)
|
data.Init(tools.RESOURCE_MODEL, caller)
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package datacenter
|
package compute
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
@ -8,18 +8,53 @@ import (
|
|||||||
"cloud.o-forge.io/core/oc-lib/tools"
|
"cloud.o-forge.io/core/oc-lib/tools"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type TechnologyEnum int
|
||||||
|
|
||||||
|
const (
|
||||||
|
DOCKER TechnologyEnum = iota
|
||||||
|
KUBERNETES
|
||||||
|
SLURM
|
||||||
|
HW
|
||||||
|
CONDOR
|
||||||
|
)
|
||||||
|
|
||||||
|
func (t TechnologyEnum) String() string {
|
||||||
|
return [...]string{"DOCKER", "KUBERNETES", "SLURM", "HW", "CONDOR"}[t]
|
||||||
|
}
|
||||||
|
|
||||||
|
type AccessEnum int
|
||||||
|
|
||||||
|
const (
|
||||||
|
SSH AccessEnum = iota
|
||||||
|
SSH_KUBE_API
|
||||||
|
SSH_SLURM
|
||||||
|
SSH_DOCKER
|
||||||
|
OPENCLOUD
|
||||||
|
VPN
|
||||||
|
)
|
||||||
|
|
||||||
|
func (a AccessEnum) String() string {
|
||||||
|
return [...]string{"SSH", "SSH_KUBE_API", "SSH_SLURM", "SSH_DOCKER", "OPENCLOUD", "VPN"}[a]
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* DatacenterResource is a struct that represents a datacenter resource
|
* ComputeResource is a struct that represents a compute resource
|
||||||
* it defines the resource datacenter
|
* it defines the resource compute
|
||||||
*/
|
*/
|
||||||
type DatacenterResource struct {
|
type ComputeResource struct {
|
||||||
resource_model.AbstractResource
|
resource_model.AbstractResource
|
||||||
|
Technology TechnologyEnum `json:"technology" bson:"technology" default:"0"` // Technology is the technology
|
||||||
|
Architecture string `json:"architecture,omitempty" bson:"architecture,omitempty"` // Architecture is the architecture
|
||||||
|
Access AccessEnum `json:"access" bson:"access default:"0"` // Access is the access
|
||||||
|
|
||||||
|
Localisation string `json:"localisation,omitempty" bson:"localisation,omitempty"` // Localisation is the localisation
|
||||||
|
|
||||||
CPUs []*CPU `bson:"cpus,omitempty" json:"cpus,omitempty"` // CPUs is the list of CPUs
|
CPUs []*CPU `bson:"cpus,omitempty" json:"cpus,omitempty"` // CPUs is the list of CPUs
|
||||||
RAM *RAM `bson:"ram,omitempty" json:"ram,omitempty"` // RAM is the RAM
|
RAM *RAM `bson:"ram,omitempty" json:"ram,omitempty"` // RAM is the RAM
|
||||||
GPUs []*GPU `bson:"gpus,omitempty" json:"gpus,omitempty"` // GPUs is the list of GPUs
|
GPUs []*GPU `bson:"gpus,omitempty" json:"gpus,omitempty"` // GPUs is the list of GPUs
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dma *DatacenterResource) Deserialize(j map[string]interface{}) utils.DBObject {
|
func (dma *ComputeResource) Deserialize(j map[string]interface{}) utils.DBObject {
|
||||||
b, err := json.Marshal(j)
|
b, err := json.Marshal(j)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
return nil
|
||||||
@ -28,7 +63,7 @@ func (dma *DatacenterResource) Deserialize(j map[string]interface{}) utils.DBObj
|
|||||||
return dma
|
return dma
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dma *DatacenterResource) Serialize() map[string]interface{} {
|
func (dma *ComputeResource) Serialize() map[string]interface{} {
|
||||||
var m map[string]interface{}
|
var m map[string]interface{}
|
||||||
b, err := json.Marshal(dma)
|
b, err := json.Marshal(dma)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -38,9 +73,9 @@ func (dma *DatacenterResource) Serialize() map[string]interface{} {
|
|||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *DatacenterResource) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
|
func (d *ComputeResource) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
|
||||||
data := New()
|
data := New()
|
||||||
data.Init(utils.DATACENTER_RESOURCE, caller)
|
data.Init(tools.COMPUTE_RESOURCE, caller)
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package datacenter
|
package compute
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"cloud.o-forge.io/core/oc-lib/dbs"
|
"cloud.o-forge.io/core/oc-lib/dbs"
|
||||||
@ -7,39 +7,39 @@ import (
|
|||||||
"cloud.o-forge.io/core/oc-lib/models/utils"
|
"cloud.o-forge.io/core/oc-lib/models/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
type datacenterMongoAccessor struct {
|
type computeMongoAccessor struct {
|
||||||
utils.AbstractAccessor // AbstractAccessor contains the basic fields of an accessor (model, caller)
|
utils.AbstractAccessor // AbstractAccessor contains the basic fields of an accessor (model, caller)
|
||||||
}
|
}
|
||||||
|
|
||||||
// New creates a new instance of the datacenterMongoAccessor
|
// New creates a new instance of the computeMongoAccessor
|
||||||
func New() *datacenterMongoAccessor {
|
func New() *computeMongoAccessor {
|
||||||
return &datacenterMongoAccessor{}
|
return &computeMongoAccessor{}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Nothing special here, just the basic CRUD operations
|
* Nothing special here, just the basic CRUD operations
|
||||||
*/
|
*/
|
||||||
|
|
||||||
func (dca *datacenterMongoAccessor) DeleteOne(id string) (utils.DBObject, int, error) {
|
func (dca *computeMongoAccessor) DeleteOne(id string) (utils.DBObject, int, error) {
|
||||||
return dca.GenericDeleteOne(id, dca)
|
return dca.GenericDeleteOne(id, dca)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dca *datacenterMongoAccessor) UpdateOne(set utils.DBObject, id string) (utils.DBObject, int, error) {
|
func (dca *computeMongoAccessor) UpdateOne(set utils.DBObject, id string) (utils.DBObject, int, error) {
|
||||||
set.(*DatacenterResource).ResourceModel = nil
|
set.(*ComputeResource).ResourceModel = nil
|
||||||
return dca.GenericUpdateOne(set, id, dca, &DatacenterResource{})
|
return dca.GenericUpdateOne(set, id, dca, &ComputeResource{})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dca *datacenterMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject, int, error) {
|
func (dca *computeMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject, int, error) {
|
||||||
data.(*DatacenterResource).ResourceModel = nil
|
data.(*ComputeResource).ResourceModel = nil
|
||||||
return dca.GenericStoreOne(data, dca)
|
return dca.GenericStoreOne(data, dca)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dca *datacenterMongoAccessor) CopyOne(data utils.DBObject) (utils.DBObject, int, error) {
|
func (dca *computeMongoAccessor) CopyOne(data utils.DBObject) (utils.DBObject, int, error) {
|
||||||
return dca.GenericStoreOne(data, dca)
|
return dca.GenericStoreOne(data, dca)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dca *datacenterMongoAccessor) LoadOne(id string) (utils.DBObject, int, error) {
|
func (dca *computeMongoAccessor) LoadOne(id string) (utils.DBObject, int, error) {
|
||||||
var datacenter DatacenterResource
|
var compute ComputeResource
|
||||||
|
|
||||||
res_mongo, code, err := mongo.MONGOService.LoadOne(id, dca.GetType())
|
res_mongo, code, err := mongo.MONGOService.LoadOne(id, dca.GetType())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -47,23 +47,23 @@ func (dca *datacenterMongoAccessor) LoadOne(id string) (utils.DBObject, int, err
|
|||||||
return nil, code, err
|
return nil, code, err
|
||||||
}
|
}
|
||||||
|
|
||||||
res_mongo.Decode(&datacenter)
|
res_mongo.Decode(&compute)
|
||||||
accessor := (&resource_model.ResourceModel{}).GetAccessor(nil)
|
accessor := (&resource_model.ResourceModel{}).GetAccessor(nil)
|
||||||
resources, _, err := accessor.Search(nil, dca.GetType())
|
resources, _, err := accessor.Search(nil, dca.GetType())
|
||||||
if err == nil && len(resources) > 0 {
|
if err == nil && len(resources) > 0 {
|
||||||
datacenter.ResourceModel = resources[0].(*resource_model.ResourceModel)
|
compute.ResourceModel = resources[0].(*resource_model.ResourceModel)
|
||||||
}
|
}
|
||||||
return &datacenter, 200, nil
|
return &compute, 200, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (wfa datacenterMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int, error) {
|
func (wfa computeMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int, error) {
|
||||||
objs := []utils.ShallowDBObject{}
|
objs := []utils.ShallowDBObject{}
|
||||||
res_mongo, code, err := mongo.MONGOService.LoadAll(wfa.GetType())
|
res_mongo, code, err := mongo.MONGOService.LoadAll(wfa.GetType())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
wfa.Logger.Error().Msg("Could not retrieve any from db. Error: " + err.Error())
|
wfa.Logger.Error().Msg("Could not retrieve any from db. Error: " + err.Error())
|
||||||
return nil, code, err
|
return nil, code, err
|
||||||
}
|
}
|
||||||
var results []DatacenterResource
|
var results []ComputeResource
|
||||||
if err = res_mongo.All(mongo.MngoCtx, &results); err != nil {
|
if err = res_mongo.All(mongo.MngoCtx, &results); err != nil {
|
||||||
return nil, 404, err
|
return nil, 404, err
|
||||||
}
|
}
|
||||||
@ -73,12 +73,12 @@ func (wfa datacenterMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int, erro
|
|||||||
if err == nil && len(resources) > 0 {
|
if err == nil && len(resources) > 0 {
|
||||||
r.ResourceModel = resources[0].(*resource_model.ResourceModel)
|
r.ResourceModel = resources[0].(*resource_model.ResourceModel)
|
||||||
}
|
}
|
||||||
objs = append(objs, &r.AbstractResource) // only get the abstract resource !
|
objs = append(objs, &r) // only get the abstract resource !
|
||||||
}
|
}
|
||||||
return objs, 200, nil
|
return objs, 200, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (wfa *datacenterMongoAccessor) Search(filters *dbs.Filters, search string) ([]utils.ShallowDBObject, int, error) {
|
func (wfa *computeMongoAccessor) Search(filters *dbs.Filters, search string) ([]utils.ShallowDBObject, int, error) {
|
||||||
objs := []utils.ShallowDBObject{}
|
objs := []utils.ShallowDBObject{}
|
||||||
if (filters == nil || len(filters.And) == 0 || len(filters.Or) == 0) && search != "" {
|
if (filters == nil || len(filters.And) == 0 || len(filters.Or) == 0) && search != "" {
|
||||||
filters = &dbs.Filters{
|
filters = &dbs.Filters{
|
||||||
@ -96,7 +96,7 @@ func (wfa *datacenterMongoAccessor) Search(filters *dbs.Filters, search string)
|
|||||||
wfa.Logger.Error().Msg("Could not store to db. Error: " + err.Error())
|
wfa.Logger.Error().Msg("Could not store to db. Error: " + err.Error())
|
||||||
return nil, code, err
|
return nil, code, err
|
||||||
}
|
}
|
||||||
var results []DatacenterResource
|
var results []ComputeResource
|
||||||
if err = res_mongo.All(mongo.MngoCtx, &results); err != nil {
|
if err = res_mongo.All(mongo.MngoCtx, &results); err != nil {
|
||||||
return nil, 404, err
|
return nil, 404, err
|
||||||
}
|
}
|
||||||
@ -106,7 +106,7 @@ func (wfa *datacenterMongoAccessor) Search(filters *dbs.Filters, search string)
|
|||||||
if err == nil && len(resources) > 0 {
|
if err == nil && len(resources) > 0 {
|
||||||
r.ResourceModel = resources[0].(*resource_model.ResourceModel)
|
r.ResourceModel = resources[0].(*resource_model.ResourceModel)
|
||||||
}
|
}
|
||||||
objs = append(objs, &r.AbstractResource) // only get the abstract resource !
|
objs = append(objs, &r) // only get the abstract resource !
|
||||||
}
|
}
|
||||||
return objs, 200, nil
|
return objs, 200, nil
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package datacenter
|
package compute
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
@ -9,10 +9,10 @@ import (
|
|||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestStoreOneDatacenter(t *testing.T) {
|
func TestStoreOneCompute(t *testing.T) {
|
||||||
dc := DatacenterResource{
|
dc := ComputeResource{
|
||||||
AbstractResource: resource_model.AbstractResource{
|
AbstractResource: resource_model.AbstractResource{
|
||||||
AbstractObject: utils.AbstractObject{Name: "testDatacenter"},
|
AbstractObject: utils.AbstractObject{Name: "testCompute"},
|
||||||
Description: "Lorem Ipsum",
|
Description: "Lorem Ipsum",
|
||||||
Logo: "azerty.com",
|
Logo: "azerty.com",
|
||||||
Owner: "toto",
|
Owner: "toto",
|
||||||
@ -27,10 +27,10 @@ func TestStoreOneDatacenter(t *testing.T) {
|
|||||||
assert.NotEmpty(t, id)
|
assert.NotEmpty(t, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLoadOneDatacenter(t *testing.T) {
|
func TestLoadOneCompute(t *testing.T) {
|
||||||
dc := DatacenterResource{
|
dc := ComputeResource{
|
||||||
AbstractResource: resource_model.AbstractResource{
|
AbstractResource: resource_model.AbstractResource{
|
||||||
AbstractObject: utils.AbstractObject{Name: "testDatacenter"},
|
AbstractObject: utils.AbstractObject{Name: "testCompute"},
|
||||||
Description: "Lorem Ipsum",
|
Description: "Lorem Ipsum",
|
||||||
Logo: "azerty.com",
|
Logo: "azerty.com",
|
||||||
Owner: "toto",
|
Owner: "toto",
|
@ -8,14 +8,34 @@ import (
|
|||||||
"cloud.o-forge.io/core/oc-lib/tools"
|
"cloud.o-forge.io/core/oc-lib/tools"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// enum of public private or licenced data
|
||||||
|
type DataLicense int
|
||||||
|
|
||||||
|
const (
|
||||||
|
PUBLIC DataLicense = iota
|
||||||
|
PRIVATE
|
||||||
|
LICENCED
|
||||||
|
)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Struct of Usage Conditions
|
||||||
|
*/
|
||||||
|
type UsageConditions struct {
|
||||||
|
Usage string `json:"usage,omitempty" bson:"usage,omitempty" description:"usage of the data"` // Usage is the usage of the data
|
||||||
|
Actors []string `json:"actors,omitempty" bson:"actors,omitempty" description:"actors of the data"` // Actors is the actors of the data
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* DataResource is a struct that represents a data resource
|
* DataResource is a struct that represents a data resource
|
||||||
* it defines the resource data
|
* it defines the resource data
|
||||||
*/
|
*/
|
||||||
type DataResource struct {
|
type DataResource struct {
|
||||||
resource_model.AbstractResource // AbstractResource contains the basic fields of an object (id, name)
|
resource_model.AbstractResource // AbstractResource contains the basic fields of an object (id, name)
|
||||||
Protocols []string `json:"protocol,omitempty" bson:"protocol,omitempty"` //TODO Enum type
|
resource_model.WebResource
|
||||||
DataType string `json:"datatype,omitempty" bson:"datatype,omitempty"` // DataType is the type of the data
|
Type string `bson:"type,omitempty" json:"type,omitempty"` // Type is the type of the storage
|
||||||
|
UsageConditions UsageConditions `json:"usage_conditions,omitempty" bson:"usage_conditions,omitempty" description:"usage conditions of the data"` // UsageConditions is the usage conditions of the data
|
||||||
|
License DataLicense `json:"license" bson:"license" description:"license of the data" default:"0"` // License is the license of the data
|
||||||
|
Interest DataLicense `json:"interest" bson:"interest" description:"interest of the data" default:"0"` // Interest is the interest of the data
|
||||||
Example string `json:"example,omitempty" bson:"example,omitempty" description:"base64 encoded data"` // Example is an example of the data
|
Example string `json:"example,omitempty" bson:"example,omitempty" description:"base64 encoded data"` // Example is an example of the data
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,6 +60,6 @@ func (dma *DataResource) Serialize() map[string]interface{} {
|
|||||||
|
|
||||||
func (d *DataResource) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
|
func (d *DataResource) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
|
||||||
data := New() // Create a new instance of the accessor
|
data := New() // Create a new instance of the accessor
|
||||||
data.Init(utils.DATA_RESOURCE, caller) // Initialize the accessor with the DATA_RESOURCE model type
|
data.Init(tools.DATA_RESOURCE, caller) // Initialize the accessor with the DATA_RESOURCE model type
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
@ -71,7 +71,7 @@ func (wfa dataMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int, error) {
|
|||||||
if err == nil && len(resources) > 0 {
|
if err == nil && len(resources) > 0 {
|
||||||
r.ResourceModel = resources[0].(*resource_model.ResourceModel)
|
r.ResourceModel = resources[0].(*resource_model.ResourceModel)
|
||||||
}
|
}
|
||||||
objs = append(objs, &r.AbstractResource) // only get the abstract resource !
|
objs = append(objs, &r) // only get the abstract resource !
|
||||||
}
|
}
|
||||||
return objs, 200, nil
|
return objs, 200, nil
|
||||||
}
|
}
|
||||||
@ -104,7 +104,7 @@ func (wfa *dataMongoAccessor) Search(filters *dbs.Filters, search string) ([]uti
|
|||||||
if err == nil && len(resources) > 0 {
|
if err == nil && len(resources) > 0 {
|
||||||
r.ResourceModel = resources[0].(*resource_model.ResourceModel)
|
r.ResourceModel = resources[0].(*resource_model.ResourceModel)
|
||||||
}
|
}
|
||||||
objs = append(objs, &r.AbstractResource) // only get the abstract resource !
|
objs = append(objs, &r) // only get the abstract resource !
|
||||||
}
|
}
|
||||||
return objs, 200, nil
|
return objs, 200, nil
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestStoreOneData(t *testing.T) {
|
func TestStoreOneData(t *testing.T) {
|
||||||
d := DataResource{DataType: "jpeg", Example: "123456",
|
d := DataResource{
|
||||||
|
WebResource: resource_model.WebResource{
|
||||||
|
Protocol: "http", Path: "azerty.fr",
|
||||||
|
},
|
||||||
|
Example: "123456",
|
||||||
AbstractResource: resource_model.AbstractResource{
|
AbstractResource: resource_model.AbstractResource{
|
||||||
AbstractObject: utils.AbstractObject{Name: "testData"},
|
AbstractObject: utils.AbstractObject{Name: "testData"},
|
||||||
Description: "Lorem Ipsum",
|
Description: "Lorem Ipsum",
|
||||||
@ -28,7 +32,11 @@ func TestStoreOneData(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestLoadOneDate(t *testing.T) {
|
func TestLoadOneDate(t *testing.T) {
|
||||||
d := DataResource{DataType: "jpeg", Example: "123456",
|
d := DataResource{
|
||||||
|
WebResource: resource_model.WebResource{
|
||||||
|
Protocol: "http", Path: "azerty.fr",
|
||||||
|
},
|
||||||
|
Example: "123456",
|
||||||
AbstractResource: resource_model.AbstractResource{
|
AbstractResource: resource_model.AbstractResource{
|
||||||
AbstractObject: utils.AbstractObject{Name: "testData"},
|
AbstractObject: utils.AbstractObject{Name: "testData"},
|
||||||
Description: "Lorem Ipsum",
|
Description: "Lorem Ipsum",
|
||||||
|
@ -4,24 +4,41 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
|
||||||
"cloud.o-forge.io/core/oc-lib/models/resource_model"
|
"cloud.o-forge.io/core/oc-lib/models/resource_model"
|
||||||
"cloud.o-forge.io/core/oc-lib/models/resources/datacenter"
|
"cloud.o-forge.io/core/oc-lib/models/resources/compute"
|
||||||
"cloud.o-forge.io/core/oc-lib/models/utils"
|
"cloud.o-forge.io/core/oc-lib/models/utils"
|
||||||
"cloud.o-forge.io/core/oc-lib/tools"
|
"cloud.o-forge.io/core/oc-lib/tools"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type Container struct {
|
||||||
|
Image string `json:"image,omitempty" bson:"image,omitempty"` // Image is the container image
|
||||||
|
Command string `json:"command,omitempty" bson:"command,omitempty"` // Command is the container command
|
||||||
|
Args string `json:"args,omitempty" bson:"args,omitempty"` // Args is the container arguments
|
||||||
|
Env map[string]string `json:"env,omitempty" bson:"env,omitempty"` // Env is the container environment variables
|
||||||
|
Volumes map[string]string `json:"volumes,omitempty" bson:"volumes,omitempty"` // Volumes is the container volumes
|
||||||
|
}
|
||||||
|
|
||||||
|
type Expose struct {
|
||||||
|
Port int `json:"port,omitempty" bson:"port,omitempty"` // Port is the port
|
||||||
|
Reverse string `json:"reverse,omitempty" bson:"reverse,omitempty"` // Reverse is the reverse
|
||||||
|
PAT int `json:"pat,omitempty" bson:"pat,omitempty"` // PAT is the PAT
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ProcessingResource is a struct that represents a processing resource
|
* ProcessingResource is a struct that represents a processing resource
|
||||||
* it defines the resource processing
|
* it defines the resource processing
|
||||||
*/
|
*/
|
||||||
type ProcessingResource struct {
|
type ProcessingResource struct {
|
||||||
resource_model.AbstractResource
|
resource_model.AbstractResource
|
||||||
CPUs []*datacenter.CPU `bson:"cpus,omitempty" json:"cp_us,omitempty"` // CPUs is the list of CPUs
|
IsService bool `json:"is_service,omitempty" bson:"is_service,omitempty"` // IsService is a flag that indicates if the processing is a service
|
||||||
GPUs []*datacenter.GPU `bson:"gpus,omitempty" json:"gp_us,omitempty"` // GPUs is the list of GPUs
|
CPUs []*compute.CPU `bson:"cpus,omitempty" json:"cp_us,omitempty"` // CPUs is the list of CPUs
|
||||||
RAM *datacenter.RAM `bson:"ram,omitempty" json:"ram,omitempty"` // RAM is the RAM
|
GPUs []*compute.GPU `bson:"gpus,omitempty" json:"gp_us,omitempty"` // GPUs is the list of GPUs
|
||||||
|
RAM *compute.RAM `bson:"ram,omitempty" json:"ram,omitempty"` // RAM is the RAM
|
||||||
Storage uint `bson:"storage,omitempty" json:"storage,omitempty"` // Storage is the storage
|
Storage uint `bson:"storage,omitempty" json:"storage,omitempty"` // Storage is the storage
|
||||||
Parallel bool `bson:"parallel,omitempty" json:"parallel,omitempty"` // Parallel is a flag that indicates if the processing is parallel
|
Parallel bool `bson:"parallel,omitempty" json:"parallel,omitempty"` // Parallel is a flag that indicates if the processing is parallel
|
||||||
ScalingModel uint `bson:"scaling_model,omitempty" json:"scaling_model,omitempty"` // ScalingModel is the scaling model
|
ScalingModel uint `bson:"scaling_model,omitempty" json:"scaling_model,omitempty"` // ScalingModel is the scaling model
|
||||||
DiskIO string `bson:"disk_io,omitempty" json:"disk_io,omitempty"` // DiskIO is the disk IO
|
DiskIO string `bson:"disk_io,omitempty" json:"disk_io,omitempty"` // DiskIO is the disk IO
|
||||||
|
Container *Container `bson:"container,omitempty" json:"container,omitempty"` // Container is the container
|
||||||
|
Expose []Expose `bson:"expose,omitempty" json:"expose,omitempty"` // Expose is the execution
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dma *ProcessingResource) Deserialize(j map[string]interface{}) utils.DBObject {
|
func (dma *ProcessingResource) Deserialize(j map[string]interface{}) utils.DBObject {
|
||||||
@ -45,6 +62,6 @@ func (dma *ProcessingResource) Serialize() map[string]interface{} {
|
|||||||
|
|
||||||
func (d *ProcessingResource) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
|
func (d *ProcessingResource) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
|
||||||
data := New() // Create a new instance of the accessor
|
data := New() // Create a new instance of the accessor
|
||||||
data.Init(utils.PROCESSING_RESOURCE, caller) // Initialize the accessor with the PROCESSING_RESOURCE model type
|
data.Init(tools.PROCESSING_RESOURCE, caller) // Initialize the accessor with the PROCESSING_RESOURCE model type
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
@ -74,7 +74,7 @@ func (wfa processingMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int, erro
|
|||||||
if err == nil && len(resources) > 0 {
|
if err == nil && len(resources) > 0 {
|
||||||
r.ResourceModel = resources[0].(*resource_model.ResourceModel)
|
r.ResourceModel = resources[0].(*resource_model.ResourceModel)
|
||||||
}
|
}
|
||||||
objs = append(objs, &r.AbstractResource) // only get the abstract resource !
|
objs = append(objs, &r) // only get the abstract resource !
|
||||||
}
|
}
|
||||||
return objs, 200, nil
|
return objs, 200, nil
|
||||||
}
|
}
|
||||||
@ -108,7 +108,7 @@ func (wfa *processingMongoAccessor) Search(filters *dbs.Filters, search string)
|
|||||||
if err == nil && len(resources) > 0 {
|
if err == nil && len(resources) > 0 {
|
||||||
r.ResourceModel = resources[0].(*resource_model.ResourceModel)
|
r.ResourceModel = resources[0].(*resource_model.ResourceModel)
|
||||||
}
|
}
|
||||||
objs = append(objs, &r.AbstractResource) // only get the abstract resource !
|
objs = append(objs, &r) // only get the abstract resource !
|
||||||
}
|
}
|
||||||
return objs, 200, nil
|
return objs, 200, nil
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ package resources
|
|||||||
import (
|
import (
|
||||||
"cloud.o-forge.io/core/oc-lib/models/resource_model"
|
"cloud.o-forge.io/core/oc-lib/models/resource_model"
|
||||||
"cloud.o-forge.io/core/oc-lib/models/resources/data"
|
"cloud.o-forge.io/core/oc-lib/models/resources/data"
|
||||||
"cloud.o-forge.io/core/oc-lib/models/resources/datacenter"
|
"cloud.o-forge.io/core/oc-lib/models/resources/compute"
|
||||||
"cloud.o-forge.io/core/oc-lib/models/resources/processing"
|
"cloud.o-forge.io/core/oc-lib/models/resources/processing"
|
||||||
"cloud.o-forge.io/core/oc-lib/models/resources/storage"
|
"cloud.o-forge.io/core/oc-lib/models/resources/storage"
|
||||||
w "cloud.o-forge.io/core/oc-lib/models/resources/workflow"
|
w "cloud.o-forge.io/core/oc-lib/models/resources/workflow"
|
||||||
@ -18,13 +18,13 @@ type ResourceSet struct {
|
|||||||
Datas []string `bson:"datas,omitempty" json:"datas,omitempty"`
|
Datas []string `bson:"datas,omitempty" json:"datas,omitempty"`
|
||||||
Storages []string `bson:"storages,omitempty" json:"storages,omitempty"`
|
Storages []string `bson:"storages,omitempty" json:"storages,omitempty"`
|
||||||
Processings []string `bson:"processings,omitempty" json:"processings,omitempty"`
|
Processings []string `bson:"processings,omitempty" json:"processings,omitempty"`
|
||||||
Datacenters []string `bson:"datacenters,omitempty" json:"datacenters,omitempty"`
|
Computes []string `bson:"computes,omitempty" json:"computes,omitempty"`
|
||||||
Workflows []string `bson:"workflows,omitempty" json:"workflows,omitempty"`
|
Workflows []string `bson:"workflows,omitempty" json:"workflows,omitempty"`
|
||||||
|
|
||||||
DataResources []*data.DataResource `bson:"-" json:"data_resources,omitempty"`
|
DataResources []*data.DataResource `bson:"-" json:"data_resources,omitempty"`
|
||||||
StorageResources []*storage.StorageResource `bson:"-" json:"storage_resources,omitempty"`
|
StorageResources []*storage.StorageResource `bson:"-" json:"storage_resources,omitempty"`
|
||||||
ProcessingResources []*processing.ProcessingResource `bson:"-" json:"processing_resources,omitempty"`
|
ProcessingResources []*processing.ProcessingResource `bson:"-" json:"processing_resources,omitempty"`
|
||||||
DatacenterResources []*datacenter.DatacenterResource `bson:"-" json:"datacenter_resources,omitempty"`
|
ComputeResources []*compute.ComputeResource `bson:"-" json:"compute_resources,omitempty"`
|
||||||
WorkflowResources []*w.WorkflowResource `bson:"-" json:"workflow_resources,omitempty"`
|
WorkflowResources []*w.WorkflowResource `bson:"-" json:"workflow_resources,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,7 +32,7 @@ type ItemResource struct {
|
|||||||
Data *data.DataResource `bson:"data,omitempty" json:"data,omitempty"`
|
Data *data.DataResource `bson:"data,omitempty" json:"data,omitempty"`
|
||||||
Processing *processing.ProcessingResource `bson:"processing,omitempty" json:"processing,omitempty"`
|
Processing *processing.ProcessingResource `bson:"processing,omitempty" json:"processing,omitempty"`
|
||||||
Storage *storage.StorageResource `bson:"storage,omitempty" json:"storage,omitempty"`
|
Storage *storage.StorageResource `bson:"storage,omitempty" json:"storage,omitempty"`
|
||||||
Datacenter *datacenter.DatacenterResource `bson:"datacenter,omitempty" json:"datacenter,omitempty"`
|
Compute *compute.ComputeResource `bson:"compute,omitempty" json:"compute,omitempty"`
|
||||||
Workflow *w.WorkflowResource `bson:"workflow,omitempty" json:"workflow,omitempty"`
|
Workflow *w.WorkflowResource `bson:"workflow,omitempty" json:"workflow,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,12 +47,11 @@ func (i *ItemResource) GetAbstractRessource() *resource_model.AbstractResource {
|
|||||||
if(i.Storage != nil){
|
if(i.Storage != nil){
|
||||||
return &i.Storage.AbstractResource
|
return &i.Storage.AbstractResource
|
||||||
}
|
}
|
||||||
if(i.Datacenter != nil){
|
if(i.Compute != nil){
|
||||||
return &i.Datacenter.AbstractResource
|
return &i.Compute.AbstractResource
|
||||||
}
|
}
|
||||||
if(i.Workflow != nil){
|
if(i.Workflow != nil){
|
||||||
return &i.Workflow.AbstractResource
|
return &i.Workflow.AbstractResource
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
@ -8,22 +8,51 @@ import (
|
|||||||
"cloud.o-forge.io/core/oc-lib/tools"
|
"cloud.o-forge.io/core/oc-lib/tools"
|
||||||
)
|
)
|
||||||
|
|
||||||
type URL struct {
|
type StorageSize int
|
||||||
Protocol string `bson:"protocol,omitempty" json:"protocol,omitempty"` // Protocol is the protocol of the URL
|
|
||||||
Path string `bson:"path,omitempty" json:"path,omitempty"` // Path is the path of the URL
|
// StorageType - Enum that defines the type of storage
|
||||||
|
const (
|
||||||
|
GB StorageSize = iota
|
||||||
|
MB
|
||||||
|
KB
|
||||||
|
)
|
||||||
|
|
||||||
|
var argoType = [...]string{
|
||||||
|
"Gi",
|
||||||
|
"Mi",
|
||||||
|
"Ki",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// New creates a new instance of the StorageResource struct
|
||||||
|
func (dma StorageSize) ToArgo() string {
|
||||||
|
return argoType[dma]
|
||||||
|
}
|
||||||
|
|
||||||
|
// enum of a data type
|
||||||
|
type StorageType int
|
||||||
|
|
||||||
|
const (
|
||||||
|
FILE = iota
|
||||||
|
STREAM
|
||||||
|
API
|
||||||
|
DATABASE
|
||||||
|
S3
|
||||||
|
MEMORY
|
||||||
|
HARDWARE
|
||||||
|
)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* StorageResource is a struct that represents a storage resource
|
* StorageResource is a struct that represents a storage resource
|
||||||
* it defines the resource storage
|
* it defines the resource storage
|
||||||
*/
|
*/
|
||||||
type StorageResource struct {
|
type StorageResource struct {
|
||||||
resource_model.AbstractResource // AbstractResource contains the basic fields of an object (id, name)
|
resource_model.AbstractResource // AbstractResource contains the basic fields of an object (id, name)
|
||||||
|
resource_model.WebResource
|
||||||
|
Type StorageType `bson:"type,omitempty" json:"type,omitempty"` // Type is the type of the storage
|
||||||
Acronym string `bson:"acronym,omitempty" json:"acronym,omitempty"` // Acronym is the acronym of the storage
|
Acronym string `bson:"acronym,omitempty" json:"acronym,omitempty"` // Acronym is the acronym of the storage
|
||||||
Type string `bson:"type,omitempty" json:"type,omitempty"` // Type is the type of the storage
|
SizeType StorageSize `bson:"size_type" json:"size_type" default:"0"` // SizeType is the type of the storage size
|
||||||
Size uint `bson:"size,omitempty" json:"size,omitempty"` // Size is the size of the storage
|
Size uint `bson:"size,omitempty" json:"size,omitempty"` // Size is the size of the storage
|
||||||
Url *URL `bson:"url,omitempty" json:"url,omitempty"` // Will allow to select between several protocols
|
Local bool `bson:"local" json:"local"` // Local is a flag that indicates if the storage is local
|
||||||
|
|
||||||
Encryption bool `bson:"encryption,omitempty" json:"encryption,omitempty"` // Encryption is a flag that indicates if the storage is encrypted
|
Encryption bool `bson:"encryption,omitempty" json:"encryption,omitempty"` // Encryption is a flag that indicates if the storage is encrypted
|
||||||
Redundancy string `bson:"redundancy,omitempty" json:"redundancy,omitempty"` // Redundancy is the redundancy of the storage
|
Redundancy string `bson:"redundancy,omitempty" json:"redundancy,omitempty"` // Redundancy is the redundancy of the storage
|
||||||
Throughput string `bson:"throughput,omitempty" json:"throughput,omitempty"` // Throughput is the throughput of the storage
|
Throughput string `bson:"throughput,omitempty" json:"throughput,omitempty"` // Throughput is the throughput of the storage
|
||||||
@ -50,6 +79,6 @@ func (dma *StorageResource) Serialize() map[string]interface{} {
|
|||||||
|
|
||||||
func (d *StorageResource) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
|
func (d *StorageResource) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
|
||||||
data := New() // Create a new instance of the accessor
|
data := New() // Create a new instance of the accessor
|
||||||
data.Init(utils.STORAGE_RESOURCE, caller) // Initialize the accessor with the STORAGE_RESOURCE model type
|
data.Init(tools.STORAGE_RESOURCE, caller) // Initialize the accessor with the STORAGE_RESOURCE model type
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
@ -74,7 +74,7 @@ func (wfa storageMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int, error)
|
|||||||
if err == nil && len(resources) > 0 {
|
if err == nil && len(resources) > 0 {
|
||||||
r.ResourceModel = resources[0].(*resource_model.ResourceModel)
|
r.ResourceModel = resources[0].(*resource_model.ResourceModel)
|
||||||
}
|
}
|
||||||
objs = append(objs, &r.AbstractResource) // only get the abstract resource !
|
objs = append(objs, &r) // only get the abstract resource !
|
||||||
}
|
}
|
||||||
return objs, 200, nil
|
return objs, 200, nil
|
||||||
}
|
}
|
||||||
@ -108,7 +108,7 @@ func (wfa *storageMongoAccessor) Search(filters *dbs.Filters, search string) ([]
|
|||||||
if err == nil && len(resources) > 0 {
|
if err == nil && len(resources) > 0 {
|
||||||
r.ResourceModel = resources[0].(*resource_model.ResourceModel)
|
r.ResourceModel = resources[0].(*resource_model.ResourceModel)
|
||||||
}
|
}
|
||||||
objs = append(objs, &r.AbstractResource) // only get the abstract resource !
|
objs = append(objs, &r) // only get the abstract resource !
|
||||||
}
|
}
|
||||||
return objs, 200, nil
|
return objs, 200, nil
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestStoreOneStorage(t *testing.T) {
|
func TestStoreOneStorage(t *testing.T) {
|
||||||
s := StorageResource{Size: 123, Url: &URL{Protocol: "http", Path: "azerty.fr"},
|
s := StorageResource{Size: 123, WebResource: resource_model.WebResource{Protocol: "http", Path: "azerty.fr"},
|
||||||
AbstractResource: resource_model.AbstractResource{
|
AbstractResource: resource_model.AbstractResource{
|
||||||
AbstractObject: utils.AbstractObject{Name: "testData"},
|
AbstractObject: utils.AbstractObject{Name: "testData"},
|
||||||
Description: "Lorem Ipsum",
|
Description: "Lorem Ipsum",
|
||||||
@ -28,7 +28,7 @@ func TestStoreOneStorage(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestLoadOneStorage(t *testing.T) {
|
func TestLoadOneStorage(t *testing.T) {
|
||||||
s := StorageResource{Size: 123, Url: &URL{Protocol: "http", Path: "azerty.fr"},
|
s := StorageResource{Size: 123, WebResource: resource_model.WebResource{Protocol: "http", Path: "azerty.fr"},
|
||||||
AbstractResource: resource_model.AbstractResource{
|
AbstractResource: resource_model.AbstractResource{
|
||||||
AbstractObject: utils.AbstractObject{Name: "testData"},
|
AbstractObject: utils.AbstractObject{Name: "testData"},
|
||||||
Description: "Lorem Ipsum",
|
Description: "Lorem Ipsum",
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
package graph
|
package graph
|
||||||
|
|
||||||
import "cloud.o-forge.io/core/oc-lib/models/resources"
|
import (
|
||||||
|
"cloud.o-forge.io/core/oc-lib/models/resources"
|
||||||
|
"cloud.o-forge.io/core/oc-lib/models/utils"
|
||||||
|
"cloud.o-forge.io/core/oc-lib/tools"
|
||||||
|
)
|
||||||
|
|
||||||
// Graph is a struct that represents a graph
|
// Graph is a struct that represents a graph
|
||||||
type Graph struct {
|
type Graph struct {
|
||||||
@ -9,6 +13,23 @@ type Graph struct {
|
|||||||
Links []GraphLink `bson:"links" json:"links" default:"{}" validate:"required"` // Links is the list of links between elements in the graph
|
Links []GraphLink `bson:"links" json:"links" default:"{}" validate:"required"` // Links is the list of links between elements in the graph
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (g *Graph) GetResource(id string) (string, utils.DBObject) {
|
||||||
|
if item, ok := g.Items[id]; ok {
|
||||||
|
if item.Data != nil {
|
||||||
|
return tools.DATA_RESOURCE.String(), item.Data
|
||||||
|
} else if item.Compute != nil {
|
||||||
|
return tools.COMPUTE_RESOURCE.String(), item.Compute
|
||||||
|
} else if item.Workflow != nil {
|
||||||
|
return tools.WORKFLOW_RESOURCE.String(), item.Workflow
|
||||||
|
} else if item.Processing != nil {
|
||||||
|
return tools.PROCESSING_RESOURCE.String(), item.Processing
|
||||||
|
} else if item.Storage != nil {
|
||||||
|
return tools.STORAGE_RESOURCE.String(), item.Storage
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "", nil
|
||||||
|
}
|
||||||
|
|
||||||
// GraphItem is a struct that represents an item in a graph
|
// GraphItem is a struct that represents an item in a graph
|
||||||
type GraphItem struct {
|
type GraphItem struct {
|
||||||
ID string `bson:"id" json:"id" validate:"required"` // ID is the unique identifier of the item
|
ID string `bson:"id" json:"id" validate:"required"` // ID is the unique identifier of the item
|
||||||
|
@ -17,7 +17,7 @@ type WorkflowResource struct {
|
|||||||
|
|
||||||
func (d *WorkflowResource) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
|
func (d *WorkflowResource) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
|
||||||
data := New() // Create a new instance of the accessor
|
data := New() // Create a new instance of the accessor
|
||||||
data.Init(utils.WORKFLOW_RESOURCE, caller) // Initialize the accessor with the WORKFLOW_RESOURCE model type
|
data.Init(tools.WORKFLOW_RESOURCE, caller) // Initialize the accessor with the WORKFLOW_RESOURCE model type
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,7 +73,7 @@ func (wfa workflowResourceMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int
|
|||||||
if err == nil && len(resources) > 0 {
|
if err == nil && len(resources) > 0 {
|
||||||
r.ResourceModel = resources[0].(*resource_model.ResourceModel)
|
r.ResourceModel = resources[0].(*resource_model.ResourceModel)
|
||||||
}
|
}
|
||||||
objs = append(objs, &r.AbstractResource)
|
objs = append(objs, &r)
|
||||||
}
|
}
|
||||||
return objs, 200, nil
|
return objs, 200, nil
|
||||||
}
|
}
|
||||||
@ -107,7 +107,7 @@ func (wfa *workflowResourceMongoAccessor) Search(filters *dbs.Filters, search st
|
|||||||
if err == nil && len(resources) > 0 {
|
if err == nil && len(resources) > 0 {
|
||||||
r.ResourceModel = resources[0].(*resource_model.ResourceModel)
|
r.ResourceModel = resources[0].(*resource_model.ResourceModel)
|
||||||
}
|
}
|
||||||
objs = append(objs, &r.AbstractResource)
|
objs = append(objs, &r)
|
||||||
}
|
}
|
||||||
return objs, 200, nil
|
return objs, 200, nil
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package utils
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
|
"time"
|
||||||
|
|
||||||
"cloud.o-forge.io/core/oc-lib/dbs"
|
"cloud.o-forge.io/core/oc-lib/dbs"
|
||||||
"cloud.o-forge.io/core/oc-lib/dbs/mongo"
|
"cloud.o-forge.io/core/oc-lib/dbs/mongo"
|
||||||
@ -24,6 +25,8 @@ var validate = validator.New(validator.WithRequiredStructEnabled())
|
|||||||
type AbstractObject struct {
|
type AbstractObject struct {
|
||||||
UUID string `json:"id,omitempty" bson:"id,omitempty" validate:"required"`
|
UUID string `json:"id,omitempty" bson:"id,omitempty" validate:"required"`
|
||||||
Name string `json:"name,omitempty" bson:"name,omitempty" validate:"required"`
|
Name string `json:"name,omitempty" bson:"name,omitempty" validate:"required"`
|
||||||
|
UpdateDate time.Time `json:"update_date" bson:"update_date"`
|
||||||
|
LastPeerWriter string `json:"last_peer_writer" bson:"last_peer_writer"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetID returns the id of the object (abstract)
|
// GetID returns the id of the object (abstract)
|
||||||
@ -36,6 +39,11 @@ func (ao *AbstractObject) GetName() string {
|
|||||||
return ao.Name
|
return ao.Name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ao *AbstractObject) UpToDate() {
|
||||||
|
ao.UpdateDate = time.Now()
|
||||||
|
// ao.LastPeerWriter, _ = static.GetMyLocalJsonPeer()
|
||||||
|
}
|
||||||
|
|
||||||
// GetAccessor returns the accessor of the object (abstract)
|
// GetAccessor returns the accessor of the object (abstract)
|
||||||
func (dma *AbstractObject) GetAccessor(caller *tools.HTTPCaller) Accessor {
|
func (dma *AbstractObject) GetAccessor(caller *tools.HTTPCaller) Accessor {
|
||||||
return nil
|
return nil
|
||||||
@ -81,7 +89,7 @@ func (dma *AbstractAccessor) GetCaller() *tools.HTTPCaller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Init initializes the accessor with the data type and the http caller
|
// Init initializes the accessor with the data type and the http caller
|
||||||
func (dma *AbstractAccessor) Init(t DataType, caller *tools.HTTPCaller) {
|
func (dma *AbstractAccessor) Init(t tools.DataType, caller *tools.HTTPCaller) {
|
||||||
dma.Logger = logs.CreateLogger(t.String()) // Create a logger with the data type
|
dma.Logger = logs.CreateLogger(t.String()) // Create a logger with the data type
|
||||||
dma.Caller = caller // Set the caller
|
dma.Caller = caller // Set the caller
|
||||||
dma.Type = t.String() // Set the data type
|
dma.Type = t.String() // Set the data type
|
||||||
|
@ -19,6 +19,7 @@ type DBObject interface {
|
|||||||
GenerateID()
|
GenerateID()
|
||||||
GetID() string
|
GetID() string
|
||||||
GetName() string
|
GetName() string
|
||||||
|
UpToDate()
|
||||||
Deserialize(j map[string]interface{}) DBObject
|
Deserialize(j map[string]interface{}) DBObject
|
||||||
Serialize() map[string]interface{}
|
Serialize() map[string]interface{}
|
||||||
GetAccessor(caller *tools.HTTPCaller) Accessor
|
GetAccessor(caller *tools.HTTPCaller) Accessor
|
||||||
@ -26,7 +27,7 @@ type DBObject interface {
|
|||||||
|
|
||||||
// Accessor is an interface that defines the basic methods for an Accessor
|
// Accessor is an interface that defines the basic methods for an Accessor
|
||||||
type Accessor interface {
|
type Accessor interface {
|
||||||
Init(t DataType, caller *tools.HTTPCaller)
|
Init(t tools.DataType, caller *tools.HTTPCaller)
|
||||||
GetType() string
|
GetType() string
|
||||||
GetCaller() *tools.HTTPCaller
|
GetCaller() *tools.HTTPCaller
|
||||||
Search(filters *dbs.Filters, search string) ([]ShallowDBObject, int, error)
|
Search(filters *dbs.Filters, search string) ([]ShallowDBObject, int, error)
|
||||||
|
@ -6,7 +6,8 @@ import (
|
|||||||
|
|
||||||
"cloud.o-forge.io/core/oc-lib/models/peer"
|
"cloud.o-forge.io/core/oc-lib/models/peer"
|
||||||
"cloud.o-forge.io/core/oc-lib/models/resources"
|
"cloud.o-forge.io/core/oc-lib/models/resources"
|
||||||
"cloud.o-forge.io/core/oc-lib/models/resources/datacenter"
|
"cloud.o-forge.io/core/oc-lib/models/resources/compute"
|
||||||
|
"cloud.o-forge.io/core/oc-lib/models/resources/storage"
|
||||||
"cloud.o-forge.io/core/oc-lib/models/resources/workflow/graph"
|
"cloud.o-forge.io/core/oc-lib/models/resources/workflow/graph"
|
||||||
"cloud.o-forge.io/core/oc-lib/models/utils"
|
"cloud.o-forge.io/core/oc-lib/models/utils"
|
||||||
"cloud.o-forge.io/core/oc-lib/tools"
|
"cloud.o-forge.io/core/oc-lib/tools"
|
||||||
@ -26,16 +27,50 @@ type AbstractWorkflow struct {
|
|||||||
Shared []string `json:"shared,omitempty" bson:"shared,omitempty"` // Shared is the ID of the shared workflow
|
Shared []string `json:"shared,omitempty" bson:"shared,omitempty"` // Shared is the ID of the shared workflow
|
||||||
}
|
}
|
||||||
|
|
||||||
// tool function to check if a link is a link between a datacenter and a resource
|
func (w *AbstractWorkflow) GetWorkflows() (list_computings []graph.GraphItem) {
|
||||||
|
for _, item := range w.Graph.Items {
|
||||||
|
if item.Workflow != nil {
|
||||||
|
list_computings = append(list_computings, item)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *AbstractWorkflow) GetStoragesByRelatedProcessing(processingID string) []*storage.StorageResource {
|
||||||
|
storages := []*storage.StorageResource{}
|
||||||
|
for _, link := range w.Graph.Links {
|
||||||
|
nodeID := link.Destination.ID // we considers that the processing is the destination
|
||||||
|
node := w.Graph.Items[link.Source.ID].Storage // we are looking for the storage as source
|
||||||
|
if node == nil { // if the source is not a storage, we consider that the destination is the storage
|
||||||
|
nodeID = link.Source.ID // and the processing is the source
|
||||||
|
node = w.Graph.Items[link.Destination.ID].Storage // we are looking for the storage as destination
|
||||||
|
}
|
||||||
|
if processingID == nodeID && node != nil { // if the storage is linked to the processing
|
||||||
|
storages = append(storages, node)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return storages
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *AbstractWorkflow) GetProcessings() (list_computings []graph.GraphItem) {
|
||||||
|
for _, item := range w.Graph.Items {
|
||||||
|
if item.Processing != nil {
|
||||||
|
list_computings = append(list_computings, item)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// tool function to check if a link is a link between a compute and a resource
|
||||||
func (w *AbstractWorkflow) isDCLink(link graph.GraphLink) (bool, string) {
|
func (w *AbstractWorkflow) isDCLink(link graph.GraphLink) (bool, string) {
|
||||||
if w.Graph == nil || w.Graph.Items == nil {
|
if w.Graph == nil || w.Graph.Items == nil {
|
||||||
return false, ""
|
return false, ""
|
||||||
}
|
}
|
||||||
if d, ok := w.Graph.Items[link.Source.ID]; ok && d.Datacenter != nil {
|
if d, ok := w.Graph.Items[link.Source.ID]; ok && d.Compute != nil {
|
||||||
return true, d.Datacenter.UUID
|
return true, d.Compute.UUID
|
||||||
}
|
}
|
||||||
if d, ok := w.Graph.Items[link.Destination.ID]; ok && d.Datacenter != nil {
|
if d, ok := w.Graph.Items[link.Destination.ID]; ok && d.Compute != nil {
|
||||||
return true, d.Datacenter.UUID
|
return true, d.Compute.UUID
|
||||||
}
|
}
|
||||||
return false, ""
|
return false, ""
|
||||||
}
|
}
|
||||||
@ -57,19 +92,19 @@ func (wfa *Workflow) CheckBooking(caller *tools.HTTPCaller) (bool, error) {
|
|||||||
if wfa.Graph == nil { // no graph no booking
|
if wfa.Graph == nil { // no graph no booking
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
accessor := (&datacenter.DatacenterResource{}).GetAccessor(nil)
|
accessor := (&compute.ComputeResource{}).GetAccessor(nil)
|
||||||
for _, link := range wfa.Graph.Links {
|
for _, link := range wfa.Graph.Links {
|
||||||
if ok, dc_id := wfa.isDCLink(link); ok { // check if the link is a link between a datacenter and a resource
|
if ok, dc_id := wfa.isDCLink(link); ok { // check if the link is a link between a compute and a resource
|
||||||
dc, code, _ := accessor.LoadOne(dc_id)
|
dc, code, _ := accessor.LoadOne(dc_id)
|
||||||
if code != 200 {
|
if code != 200 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// CHECK BOOKING ON PEER, datacenter could be a remote one
|
// CHECK BOOKING ON PEER, compute could be a remote one
|
||||||
peerID := dc.(*datacenter.DatacenterResource).PeerID
|
peerID := dc.(*compute.ComputeResource).PeerID
|
||||||
if peerID == "" {
|
if peerID == "" {
|
||||||
return false, errors.New("no peer id")
|
return false, errors.New("no peer id")
|
||||||
} // no peer id no booking, we need to know where to book
|
} // no peer id no booking, we need to know where to book
|
||||||
_, err := (&peer.Peer{}).LaunchPeerExecution(peerID, dc_id, utils.BOOKING, tools.GET, nil, caller)
|
_, err := (&peer.Peer{}).LaunchPeerExecution(peerID, dc_id, tools.BOOKING, tools.GET, nil, caller)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
@ -84,7 +119,7 @@ func (d *Workflow) GetName() string {
|
|||||||
|
|
||||||
func (d *Workflow) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
|
func (d *Workflow) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
|
||||||
data := New() // Create a new instance of the accessor
|
data := New() // Create a new instance of the accessor
|
||||||
data.Init(utils.WORKFLOW, caller) // Initialize the accessor with the WORKFLOW model type
|
data.Init(tools.WORKFLOW, caller) // Initialize the accessor with the WORKFLOW model type
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
34
models/workflow/workflow_history_mongo_accessor.go
Normal file
34
models/workflow/workflow_history_mongo_accessor.go
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
package workflow
|
||||||
|
|
||||||
|
import (
|
||||||
|
"cloud.o-forge.io/core/oc-lib/models/utils"
|
||||||
|
"cloud.o-forge.io/core/oc-lib/tools"
|
||||||
|
"github.com/google/uuid"
|
||||||
|
)
|
||||||
|
|
||||||
|
type WorkflowHistory struct{ Workflow }
|
||||||
|
|
||||||
|
func (d *WorkflowHistory) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
|
||||||
|
data := New() // Create a new instance of the accessor
|
||||||
|
data.Init(tools.WORKSPACE_HISTORY, caller) // Initialize the accessor with the WORKSPACE model type
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
func (r *WorkflowHistory) GenerateID() {
|
||||||
|
r.UUID = uuid.New().String()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Workspace is a struct that represents a workspace
|
||||||
|
type workflowHistoryMongoAccessor struct {
|
||||||
|
workflowMongoAccessor // AbstractAccessor contains the basic fields of an accessor (model, caller)
|
||||||
|
}
|
||||||
|
|
||||||
|
// New creates a new instance of the workspaceMongoAccessor
|
||||||
|
func NewHistory() *workflowHistoryMongoAccessor {
|
||||||
|
return &workflowHistoryMongoAccessor{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *workflowHistoryMongoAccessor) MapFromWorkflow(w *Workflow) *WorkflowHistory {
|
||||||
|
wh := &WorkflowHistory{Workflow: *w}
|
||||||
|
wh.GenerateID()
|
||||||
|
return wh
|
||||||
|
}
|
@ -2,17 +2,18 @@ package workflow
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"cloud.o-forge.io/core/oc-lib/dbs"
|
"cloud.o-forge.io/core/oc-lib/dbs"
|
||||||
"cloud.o-forge.io/core/oc-lib/dbs/mongo"
|
"cloud.o-forge.io/core/oc-lib/dbs/mongo"
|
||||||
|
"cloud.o-forge.io/core/oc-lib/models/collaborative_area/shallow_collaborative_area"
|
||||||
"cloud.o-forge.io/core/oc-lib/models/peer"
|
"cloud.o-forge.io/core/oc-lib/models/peer"
|
||||||
"cloud.o-forge.io/core/oc-lib/models/resources"
|
"cloud.o-forge.io/core/oc-lib/models/resources"
|
||||||
"cloud.o-forge.io/core/oc-lib/models/resources/datacenter"
|
"cloud.o-forge.io/core/oc-lib/models/resources/compute"
|
||||||
"cloud.o-forge.io/core/oc-lib/models/utils"
|
"cloud.o-forge.io/core/oc-lib/models/utils"
|
||||||
"cloud.o-forge.io/core/oc-lib/models/workflow_execution"
|
"cloud.o-forge.io/core/oc-lib/models/workflow_execution"
|
||||||
"cloud.o-forge.io/core/oc-lib/models/workspace"
|
"cloud.o-forge.io/core/oc-lib/models/workspace"
|
||||||
"cloud.o-forge.io/core/oc-lib/models/workspace/shared/shallow_shared_workspace"
|
|
||||||
"cloud.o-forge.io/core/oc-lib/tools"
|
"cloud.o-forge.io/core/oc-lib/tools"
|
||||||
cron "github.com/robfig/cron/v3"
|
cron "github.com/robfig/cron/v3"
|
||||||
)
|
)
|
||||||
@ -95,9 +96,9 @@ func (wfa *workflowMongoAccessor) DeleteOne(id string) (utils.DBObject, int, err
|
|||||||
}, true) // delete the executions
|
}, true) // delete the executions
|
||||||
res, code, err := wfa.GenericDeleteOne(id, wfa)
|
res, code, err := wfa.GenericDeleteOne(id, wfa)
|
||||||
if res != nil && code == 200 {
|
if res != nil && code == 200 {
|
||||||
wfa.execute(res.(*Workflow), false) // up to date the workspace for the workflow
|
wfa.execute(res.(*Workflow), true, false) // up to date the workspace for the workflow
|
||||||
|
wfa.share(res.(*Workflow), true, wfa.Caller)
|
||||||
}
|
}
|
||||||
wfa.share(res.(*Workflow), true, wfa.Caller) // send the deletion to the peers where workflow is shared
|
|
||||||
return res, code, err
|
return res, code, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,10 +108,10 @@ func (wfa *workflowMongoAccessor) DeleteOne(id string) (utils.DBObject, int, err
|
|||||||
* it returns an error if the booking fails
|
* it returns an error if the booking fails
|
||||||
*/
|
*/
|
||||||
func (wfa *workflowMongoAccessor) book(id string, realData *Workflow, execs []*workflow_execution.WorkflowExecution) error {
|
func (wfa *workflowMongoAccessor) book(id string, realData *Workflow, execs []*workflow_execution.WorkflowExecution) error {
|
||||||
if wfa.Caller == nil || wfa.Caller.URLS == nil || wfa.Caller.URLS[utils.BOOKING.String()] == nil {
|
if wfa.Caller == nil || wfa.Caller.URLS == nil || wfa.Caller.URLS[tools.BOOKING] == nil {
|
||||||
return errors.New("no caller defined")
|
return errors.New("no caller defined")
|
||||||
}
|
}
|
||||||
methods := wfa.Caller.URLS[utils.BOOKING.String()]
|
methods := wfa.Caller.URLS[tools.BOOKING]
|
||||||
if _, ok := methods[tools.POST]; !ok {
|
if _, ok := methods[tools.POST]; !ok {
|
||||||
return errors.New("no path found")
|
return errors.New("no path found")
|
||||||
}
|
}
|
||||||
@ -124,26 +125,27 @@ func (wfa *workflowMongoAccessor) book(id string, realData *Workflow, execs []*w
|
|||||||
g = realData.Graph
|
g = realData.Graph
|
||||||
}
|
}
|
||||||
if g != nil && g.Links != nil && len(g.Links) > 0 { // if the graph is set and has links then book the workflow (even on ourselves)
|
if g != nil && g.Links != nil && len(g.Links) > 0 { // if the graph is set and has links then book the workflow (even on ourselves)
|
||||||
accessor := (&datacenter.DatacenterResource{}).GetAccessor(nil)
|
accessor := (&compute.ComputeResource{}).GetAccessor(nil)
|
||||||
for _, link := range g.Links {
|
for _, link := range g.Links {
|
||||||
if ok, dc_id := realData.isDCLink(link); ok { // check if the link is a link between a datacenter and a resource booking is only on datacenter
|
if ok, dc_id := realData.isDCLink(link); ok { // check if the link is a link between a compute and a resource booking is only on compute
|
||||||
dc, code, _ := accessor.LoadOne(dc_id)
|
dc, code, _ := accessor.LoadOne(dc_id)
|
||||||
if code != 200 {
|
if code != 200 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// CHECK BOOKING
|
// CHECK BOOKING
|
||||||
peerID := dc.(*datacenter.DatacenterResource).PeerID
|
peerID := dc.(*compute.ComputeResource).PeerID
|
||||||
if peerID == "" { // no peer id no booking
|
if peerID == "" { // no peer id no booking
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// BOOKING ON PEER
|
// BOOKING ON PEER
|
||||||
_, err := (&peer.Peer{}).LaunchPeerExecution(peerID, "", utils.BOOKING, tools.POST,
|
_, err := (&peer.Peer{}).LaunchPeerExecution(peerID, "", tools.BOOKING, tools.POST,
|
||||||
(&workflow_execution.WorkflowExecutions{ // it's the standard model for booking see OC-PEER
|
(&workflow_execution.WorkflowExecutions{ // it's the standard model for booking see OC-PEER
|
||||||
WorkflowID: id, // set the workflow id "WHO"
|
WorkflowID: id, // set the workflow id "WHO"
|
||||||
ResourceID: dc_id, // set the datacenter id "WHERE"
|
ResourceID: dc_id, // set the compute id "WHERE"
|
||||||
Executions: execs, // set the executions to book "WHAT"
|
Executions: execs, // set the executions to book "WHAT"
|
||||||
}).Serialize(), wfa.Caller)
|
}).Serialize(), wfa.Caller)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
fmt.Println("BOOKING", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -156,26 +158,28 @@ func (wfa *workflowMongoAccessor) book(id string, realData *Workflow, execs []*w
|
|||||||
* share is a function that shares a workflow to the peers if the workflow is shared
|
* share is a function that shares a workflow to the peers if the workflow is shared
|
||||||
*/
|
*/
|
||||||
func (wfa *workflowMongoAccessor) share(realData *Workflow, delete bool, caller *tools.HTTPCaller) {
|
func (wfa *workflowMongoAccessor) share(realData *Workflow, delete bool, caller *tools.HTTPCaller) {
|
||||||
if realData.Shared == nil || len(realData.Shared) == 0 { // no shared no sharing
|
if realData.Shared == nil || len(realData.Shared) == 0 || caller.Disabled { // no shared no sharing
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
for _, sharedID := range realData.Shared { // loop through the shared ids
|
for _, sharedID := range realData.Shared { // loop through the shared ids
|
||||||
access := (&shallow_shared_workspace.ShallowSharedWorkspace{}).GetAccessor(nil)
|
access := (&shallow_collaborative_area.ShallowCollaborativeArea{}).GetAccessor(nil)
|
||||||
res, code, _ := access.LoadOne(sharedID)
|
res, code, _ := access.LoadOne(sharedID)
|
||||||
if code != 200 {
|
if code != 200 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
var err error
|
var err error
|
||||||
paccess := &peer.Peer{}
|
paccess := &peer.Peer{}
|
||||||
for _, p := range res.(*shallow_shared_workspace.ShallowSharedWorkspace).Peers {
|
for _, p := range res.(*shallow_collaborative_area.ShallowCollaborativeArea).Peers {
|
||||||
paccess.UUID = p
|
paccess.UUID = p
|
||||||
if paccess.IsMySelf() { // if the peer is the current peer, never share because it will create a loop
|
if ok, _ := paccess.IsMySelf(); ok { // if the peer is the current peer, never share because it will create a loop
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if delete { // if the workflow is deleted, share the deletion
|
if delete { // if the workflow is deleted, share the deletion
|
||||||
_, err = paccess.LaunchPeerExecution(p, res.GetID(), utils.WORKFLOW, tools.DELETE, map[string]interface{}{}, caller)
|
history := NewHistory()
|
||||||
|
history.StoreOne(history.MapFromWorkflow(res.(*Workflow)))
|
||||||
|
_, err = paccess.LaunchPeerExecution(p, res.GetID(), tools.WORKFLOW, tools.DELETE, map[string]interface{}{}, caller)
|
||||||
} else { // if the workflow is updated, share the update
|
} else { // if the workflow is updated, share the update
|
||||||
_, err = paccess.LaunchPeerExecution(p, res.GetID(), utils.WORKFLOW, tools.PUT, res.Serialize(), caller)
|
_, err = paccess.LaunchPeerExecution(p, res.GetID(), tools.WORKFLOW, tools.PUT, res.Serialize(), caller)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -188,46 +192,40 @@ func (wfa *workflowMongoAccessor) share(realData *Workflow, delete bool, caller
|
|||||||
* execution is a create or delete function for the workflow executions depending on the schedule of the workflow
|
* execution is a create or delete function for the workflow executions depending on the schedule of the workflow
|
||||||
*/
|
*/
|
||||||
func (wfa *workflowMongoAccessor) execution(id string, realData *Workflow, delete bool) (int, error) {
|
func (wfa *workflowMongoAccessor) execution(id string, realData *Workflow, delete bool) (int, error) {
|
||||||
var err error
|
|
||||||
nats := tools.NewNATSCaller() // create a new nats caller because executions are sent to the nats for daemons
|
nats := tools.NewNATSCaller() // create a new nats caller because executions are sent to the nats for daemons
|
||||||
if !realData.ScheduleActive { // if the schedule is not active, delete the executions
|
|
||||||
mongo.MONGOService.DeleteMultiple(map[string]interface{}{
|
mongo.MONGOService.DeleteMultiple(map[string]interface{}{
|
||||||
"state": 1, // only delete the scheduled executions only scheduled if executions are in progress or ended, they should not be deleted for registration
|
"state": 1, // only delete the scheduled executions only scheduled if executions are in progress or ended, they should not be deleted for registration
|
||||||
"workflow_id": id,
|
"workflow_id": id,
|
||||||
}, utils.WORKFLOW_EXECUTION.String())
|
}, tools.WORKFLOW_EXECUTION.String())
|
||||||
err := wfa.book(id, realData, []*workflow_execution.WorkflowExecution{}) // delete the booking of the workflow on the peers
|
err := wfa.book(id, realData, []*workflow_execution.WorkflowExecution{}) // delete the booking of the workflow on the peers
|
||||||
nats.SetNATSPub(utils.WORKFLOW.String(), tools.REMOVE, realData) // send the deletion to the nats
|
fmt.Println("DELETE BOOKING", err)
|
||||||
return 200, err
|
nats.SetNATSPub(tools.WORKFLOW.String(), tools.REMOVE, realData) // send the deletion to the nats
|
||||||
|
if err != nil {
|
||||||
|
return 409, err
|
||||||
}
|
}
|
||||||
|
|
||||||
accessor := (&workflow_execution.WorkflowExecution{}).GetAccessor(nil)
|
accessor := (&workflow_execution.WorkflowExecution{}).GetAccessor(nil)
|
||||||
execs, err := wfa.getExecutions(id, realData) // get the executions of the workflow
|
execs, err := wfa.getExecutions(id, realData) // get the executions of the workflow
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 422, err
|
return 422, err
|
||||||
}
|
}
|
||||||
|
if !realData.ScheduleActive || delete { // if the schedule is not active, delete the executions
|
||||||
|
execs = []*workflow_execution.WorkflowExecution{}
|
||||||
|
}
|
||||||
err = wfa.book(id, realData, execs) // book the workflow on the peers
|
err = wfa.book(id, realData, execs) // book the workflow on the peers
|
||||||
|
fmt.Println("BOOKING", err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 409, err // if the booking fails, return an error for integrity between peers
|
return 409, err // if the booking fails, return an error for integrity between peers
|
||||||
}
|
}
|
||||||
if delete { // if delete is set to true, delete the executions
|
fmt.Println("BOOKING", delete)
|
||||||
mongo.MONGOService.DeleteMultiple(map[string]interface{}{
|
|
||||||
"workflow_id": id,
|
|
||||||
"state": 1,
|
|
||||||
}, utils.WORKFLOW_EXECUTION.String())
|
|
||||||
wfa.book(id, realData, []*workflow_execution.WorkflowExecution{})
|
|
||||||
nats.SetNATSPub(utils.WORKFLOW.String(), tools.REMOVE, realData)
|
|
||||||
return 200, nil
|
|
||||||
}
|
|
||||||
if len(execs) > 0 { // if the executions are set, store them
|
|
||||||
for _, obj := range execs {
|
for _, obj := range execs {
|
||||||
_, code, err := accessor.StoreOne(obj)
|
_, code, err := accessor.StoreOne(obj)
|
||||||
|
fmt.Println("EXEC", code, err)
|
||||||
if code != 200 {
|
if code != 200 {
|
||||||
return code, err
|
return code, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
nats.SetNATSPub(utils.WORKFLOW.String(), tools.CREATE, realData) // send the creation to the nats
|
nats.SetNATSPub(tools.WORKFLOW.String(), tools.CREATE, realData) // send the creation to the nats
|
||||||
} else {
|
|
||||||
return 422, err
|
|
||||||
}
|
|
||||||
return 200, nil
|
return 200, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -243,20 +241,21 @@ func (wfa *workflowMongoAccessor) UpdateOne(set utils.DBObject, id string) (util
|
|||||||
if code != 200 {
|
if code != 200 {
|
||||||
return nil, code, err
|
return nil, code, err
|
||||||
}
|
}
|
||||||
|
fmt.Println("UPDATE", avoid, res.(*Workflow).ScheduleActive)
|
||||||
if !avoid { // if the schedule is not avoided, update the executions
|
if !avoid { // if the schedule is not avoided, update the executions
|
||||||
if code, err := wfa.execution(id, res.(*Workflow), true); err != nil {
|
if code, err := wfa.execution(id, res.(*Workflow), false); code != 200 {
|
||||||
return nil, code, err
|
return nil, code, errors.New("could not update the executions : " + err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
wfa.execute(res.(*Workflow), false) // update the workspace for the workflow
|
wfa.execute(res.(*Workflow), false, false) // update the workspace for the workflow
|
||||||
wfa.share(res.(*Workflow), false, wfa.Caller) // share the update to the peers
|
wfa.share(res.(*Workflow), false, wfa.Caller) // share the update to the peers
|
||||||
return res, code, err
|
return res, code, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// StoreOne stores a workflow in the database
|
// StoreOne stores a workflow in the database
|
||||||
func (wfa *workflowMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject, int, error) {
|
func (wfa *workflowMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject, int, error) {
|
||||||
res, code, err := wfa.GenericStoreOne(data, wfa)
|
res, code, err := wfa.GenericStoreOne(data, wfa)
|
||||||
if err != nil {
|
if err != nil || code != 200 {
|
||||||
return nil, code, err
|
return nil, code, err
|
||||||
}
|
}
|
||||||
wfa.share(res.(*Workflow), false, wfa.Caller) // share the creation to the peers
|
wfa.share(res.(*Workflow), false, wfa.Caller) // share the creation to the peers
|
||||||
@ -264,8 +263,8 @@ func (wfa *workflowMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject,
|
|||||||
if code, err := wfa.execution(res.GetID(), res.(*Workflow), false); err != nil {
|
if code, err := wfa.execution(res.GetID(), res.(*Workflow), false); err != nil {
|
||||||
return nil, code, err
|
return nil, code, err
|
||||||
}
|
}
|
||||||
wfa.execute(res.(*Workflow), false) // store the workspace for the workflow
|
wfa.execute(res.(*Workflow), false, false) // store the workspace for the workflow
|
||||||
return res, code, err
|
return res, code, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// CopyOne copies a workflow in the database
|
// CopyOne copies a workflow in the database
|
||||||
@ -275,7 +274,7 @@ func (wfa *workflowMongoAccessor) CopyOne(data utils.DBObject) (utils.DBObject,
|
|||||||
|
|
||||||
// execute is a function that executes a workflow
|
// execute is a function that executes a workflow
|
||||||
// it stores the workflow resources in a specific workspace to never have a conflict in UI and logic
|
// it stores the workflow resources in a specific workspace to never have a conflict in UI and logic
|
||||||
func (wfa *workflowMongoAccessor) execute(workflow *Workflow, delete bool) {
|
func (wfa *workflowMongoAccessor) execute(workflow *Workflow, delete bool, active bool) {
|
||||||
|
|
||||||
accessor := (&workspace.Workspace{}).GetAccessor(nil)
|
accessor := (&workspace.Workspace{}).GetAccessor(nil)
|
||||||
filters := &dbs.Filters{
|
filters := &dbs.Filters{
|
||||||
@ -292,25 +291,25 @@ func (wfa *workflowMongoAccessor) execute(workflow *Workflow, delete bool) {
|
|||||||
}
|
}
|
||||||
if err == nil && len(resource) > 0 { // if the workspace already exists, update it
|
if err == nil && len(resource) > 0 { // if the workspace already exists, update it
|
||||||
accessor.UpdateOne(&workspace.Workspace{
|
accessor.UpdateOne(&workspace.Workspace{
|
||||||
Active: true,
|
Active: active,
|
||||||
ResourceSet: resources.ResourceSet{
|
ResourceSet: resources.ResourceSet{
|
||||||
Datas: workflow.Datas,
|
Datas: workflow.Datas,
|
||||||
Processings: workflow.Processings,
|
Processings: workflow.Processings,
|
||||||
Storages: workflow.Storages,
|
Storages: workflow.Storages,
|
||||||
Workflows: workflow.Workflows,
|
Workflows: workflow.Workflows,
|
||||||
Datacenters: workflow.Datacenters,
|
Computes: workflow.Computes,
|
||||||
},
|
},
|
||||||
}, resource[0].GetID())
|
}, resource[0].GetID())
|
||||||
} else { // if the workspace does not exist, create it
|
} else { // if the workspace does not exist, create it
|
||||||
accessor.StoreOne(&workspace.Workspace{
|
accessor.StoreOne(&workspace.Workspace{
|
||||||
Active: true,
|
Active: active,
|
||||||
AbstractObject: utils.AbstractObject{Name: workflow.Name + "_workspace"},
|
AbstractObject: utils.AbstractObject{Name: workflow.Name + "_workspace"},
|
||||||
ResourceSet: resources.ResourceSet{
|
ResourceSet: resources.ResourceSet{
|
||||||
Datas: workflow.Datas,
|
Datas: workflow.Datas,
|
||||||
Processings: workflow.Processings,
|
Processings: workflow.Processings,
|
||||||
Storages: workflow.Storages,
|
Storages: workflow.Storages,
|
||||||
Workflows: workflow.Workflows,
|
Workflows: workflow.Workflows,
|
||||||
Datacenters: workflow.Datacenters,
|
Computes: workflow.Computes,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -325,7 +324,7 @@ func (wfa *workflowMongoAccessor) LoadOne(id string) (utils.DBObject, int, error
|
|||||||
return nil, code, err
|
return nil, code, err
|
||||||
}
|
}
|
||||||
res_mongo.Decode(&workflow)
|
res_mongo.Decode(&workflow)
|
||||||
wfa.execute(&workflow, false) // if no workspace is attached to the workflow, create it
|
wfa.execute(&workflow, false, true) // if no workspace is attached to the workflow, create it
|
||||||
|
|
||||||
return &workflow, 200, nil
|
return &workflow, 200, nil
|
||||||
}
|
}
|
||||||
|
@ -85,6 +85,10 @@ type WorkflowExecution struct {
|
|||||||
WorkflowID string `json:"workflow_id" bson:"workflow_id,omitempty"` // WorkflowID is the ID of the workflow
|
WorkflowID string `json:"workflow_id" bson:"workflow_id,omitempty"` // WorkflowID is the ID of the workflow
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (wfa *WorkflowExecution) Equals(we *WorkflowExecution) bool {
|
||||||
|
return wfa.ExecDate.Equal(*we.ExecDate) && wfa.WorkflowID == we.WorkflowID
|
||||||
|
}
|
||||||
|
|
||||||
// tool to transform the argo status to a state
|
// tool to transform the argo status to a state
|
||||||
func (wfa *WorkflowExecution) ArgoStatusToState(status string) *WorkflowExecution {
|
func (wfa *WorkflowExecution) ArgoStatusToState(status string) *WorkflowExecution {
|
||||||
status = strings.ToLower(status)
|
status = strings.ToLower(status)
|
||||||
@ -115,7 +119,7 @@ func (d *WorkflowExecution) GetName() string {
|
|||||||
|
|
||||||
func (d *WorkflowExecution) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
|
func (d *WorkflowExecution) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
|
||||||
data := New() // Create a new instance of the accessor
|
data := New() // Create a new instance of the accessor
|
||||||
data.Init(utils.WORKFLOW_EXECUTION, caller) // Initialize the accessor with the WORKFLOW_EXECUTION model type
|
data.Init(tools.WORKFLOW_EXECUTION, caller) // Initialize the accessor with the WORKFLOW_EXECUTION model type
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ import (
|
|||||||
// Workspace is a struct that represents a workspace
|
// Workspace is a struct that represents a workspace
|
||||||
type Workspace struct {
|
type Workspace struct {
|
||||||
utils.AbstractObject // AbstractObject contains the basic fields of an object (id, name)
|
utils.AbstractObject // AbstractObject contains the basic fields of an object (id, name)
|
||||||
resources.ResourceSet // ResourceSet contains the resources of the workspace (data, datacenter, processing, storage, workflow)
|
resources.ResourceSet // ResourceSet contains the resources of the workspace (data, compute, processing, storage, workflow)
|
||||||
IsContextual bool `json:"is_contextual" bson:"is_contextual" default:"false"` // IsContextual is a flag that indicates if the workspace is contextual
|
IsContextual bool `json:"is_contextual" bson:"is_contextual" default:"false"` // IsContextual is a flag that indicates if the workspace is contextual
|
||||||
Active bool `json:"active" bson:"active" default:"false"` // Active is a flag that indicates if the workspace is active
|
Active bool `json:"active" bson:"active" default:"false"` // Active is a flag that indicates if the workspace is active
|
||||||
Shared string `json:"shared,omitempty" bson:"shared,omitempty"` // Shared is the ID of the shared workspace
|
Shared string `json:"shared,omitempty" bson:"shared,omitempty"` // Shared is the ID of the shared workspace
|
||||||
@ -34,7 +34,7 @@ func (d *Workspace) GetName() string {
|
|||||||
|
|
||||||
func (d *Workspace) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
|
func (d *Workspace) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
|
||||||
data := New() // Create a new instance of the accessor
|
data := New() // Create a new instance of the accessor
|
||||||
data.Init(utils.WORKSPACE, caller) // Initialize the accessor with the WORKSPACE model type
|
data.Init(tools.WORKSPACE, caller) // Initialize the accessor with the WORKSPACE model type
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
34
models/workspace/workspace_history_mongo_accessor.go
Normal file
34
models/workspace/workspace_history_mongo_accessor.go
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
package workspace
|
||||||
|
|
||||||
|
import (
|
||||||
|
"cloud.o-forge.io/core/oc-lib/models/utils"
|
||||||
|
"cloud.o-forge.io/core/oc-lib/tools"
|
||||||
|
"github.com/google/uuid"
|
||||||
|
)
|
||||||
|
|
||||||
|
type WorkspaceHistory struct{ Workspace }
|
||||||
|
|
||||||
|
func (d *WorkspaceHistory) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
|
||||||
|
data := New() // Create a new instance of the accessor
|
||||||
|
data.Init(tools.WORKSPACE_HISTORY, caller) // Initialize the accessor with the WORKSPACE model type
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
func (r *WorkspaceHistory) GenerateID() {
|
||||||
|
r.UUID = uuid.New().String()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Workspace is a struct that represents a workspace
|
||||||
|
type workspaceHistoryMongoAccessor struct {
|
||||||
|
workspaceMongoAccessor // AbstractAccessor contains the basic fields of an accessor (model, caller)
|
||||||
|
}
|
||||||
|
|
||||||
|
// New creates a new instance of the workspaceMongoAccessor
|
||||||
|
func NewHistory() *workspaceHistoryMongoAccessor {
|
||||||
|
return &workspaceHistoryMongoAccessor{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *workspaceHistoryMongoAccessor) MapFromWorkspace(w *Workspace) *WorkspaceHistory {
|
||||||
|
wh := &WorkspaceHistory{Workspace: *w}
|
||||||
|
wh.GenerateID()
|
||||||
|
return wh
|
||||||
|
}
|
@ -5,14 +5,14 @@ import (
|
|||||||
|
|
||||||
"cloud.o-forge.io/core/oc-lib/dbs"
|
"cloud.o-forge.io/core/oc-lib/dbs"
|
||||||
"cloud.o-forge.io/core/oc-lib/dbs/mongo"
|
"cloud.o-forge.io/core/oc-lib/dbs/mongo"
|
||||||
|
"cloud.o-forge.io/core/oc-lib/models/collaborative_area/shallow_collaborative_area"
|
||||||
"cloud.o-forge.io/core/oc-lib/models/peer"
|
"cloud.o-forge.io/core/oc-lib/models/peer"
|
||||||
"cloud.o-forge.io/core/oc-lib/models/resources/data"
|
"cloud.o-forge.io/core/oc-lib/models/resources/data"
|
||||||
"cloud.o-forge.io/core/oc-lib/models/resources/datacenter"
|
"cloud.o-forge.io/core/oc-lib/models/resources/compute"
|
||||||
"cloud.o-forge.io/core/oc-lib/models/resources/processing"
|
"cloud.o-forge.io/core/oc-lib/models/resources/processing"
|
||||||
"cloud.o-forge.io/core/oc-lib/models/resources/storage"
|
"cloud.o-forge.io/core/oc-lib/models/resources/storage"
|
||||||
w "cloud.o-forge.io/core/oc-lib/models/resources/workflow"
|
w "cloud.o-forge.io/core/oc-lib/models/resources/workflow"
|
||||||
"cloud.o-forge.io/core/oc-lib/models/utils"
|
"cloud.o-forge.io/core/oc-lib/models/utils"
|
||||||
"cloud.o-forge.io/core/oc-lib/models/workspace/shared/shallow_shared_workspace"
|
|
||||||
"cloud.o-forge.io/core/oc-lib/tools"
|
"cloud.o-forge.io/core/oc-lib/tools"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -30,7 +30,9 @@ func New() *workspaceMongoAccessor {
|
|||||||
// it checks if a workspace with the same name already exists
|
// it checks if a workspace with the same name already exists
|
||||||
func (wfa *workspaceMongoAccessor) DeleteOne(id string) (utils.DBObject, int, error) {
|
func (wfa *workspaceMongoAccessor) DeleteOne(id string) (utils.DBObject, int, error) {
|
||||||
res, code, err := wfa.GenericDeleteOne(id, wfa)
|
res, code, err := wfa.GenericDeleteOne(id, wfa)
|
||||||
wfa.share(res.(*Workspace), true, wfa.Caller) // Share the deletion to the peers
|
if code == 200 && res != nil {
|
||||||
|
wfa.share(res.(*Workspace), tools.DELETE, wfa.Caller) // Share the deletion to the peers
|
||||||
|
}
|
||||||
return res, code, err
|
return res, code, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,7 +40,7 @@ func (wfa *workspaceMongoAccessor) DeleteOne(id string) (utils.DBObject, int, er
|
|||||||
func (wfa *workspaceMongoAccessor) UpdateOne(set utils.DBObject, id string) (utils.DBObject, int, error) {
|
func (wfa *workspaceMongoAccessor) UpdateOne(set utils.DBObject, id string) (utils.DBObject, int, error) {
|
||||||
d := set.(*Workspace) // Get the workspace from the set
|
d := set.(*Workspace) // Get the workspace from the set
|
||||||
d.DataResources = nil // Reset the resources
|
d.DataResources = nil // Reset the resources
|
||||||
d.DatacenterResources = nil
|
d.ComputeResources = nil
|
||||||
d.StorageResources = nil
|
d.StorageResources = nil
|
||||||
d.ProcessingResources = nil
|
d.ProcessingResources = nil
|
||||||
d.WorkflowResources = nil
|
d.WorkflowResources = nil
|
||||||
@ -54,7 +56,9 @@ func (wfa *workspaceMongoAccessor) UpdateOne(set utils.DBObject, id string) (uti
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
res, code, err := wfa.GenericUpdateOne(set, id, wfa, &Workspace{})
|
res, code, err := wfa.GenericUpdateOne(set, id, wfa, &Workspace{})
|
||||||
wfa.share(res.(*Workspace), false, wfa.Caller)
|
if code == 200 && res != nil {
|
||||||
|
wfa.share(res.(*Workspace), tools.PUT, wfa.Caller)
|
||||||
|
}
|
||||||
return res, code, err
|
return res, code, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,7 +76,7 @@ func (wfa *workspaceMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject
|
|||||||
// reset the resources
|
// reset the resources
|
||||||
d := data.(*Workspace)
|
d := data.(*Workspace)
|
||||||
d.DataResources = nil
|
d.DataResources = nil
|
||||||
d.DatacenterResources = nil
|
d.ComputeResources = nil
|
||||||
d.StorageResources = nil
|
d.StorageResources = nil
|
||||||
d.ProcessingResources = nil
|
d.ProcessingResources = nil
|
||||||
d.WorkflowResources = nil
|
d.WorkflowResources = nil
|
||||||
@ -98,13 +102,13 @@ func (wfa *workspaceMongoAccessor) fill(workflow *Workspace) *Workspace {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Fill the workspace with the datacenters
|
// Fill the workspace with the computes
|
||||||
if workflow.Datacenters != nil && len(workflow.Datacenters) > 0 {
|
if workflow.Computes != nil && len(workflow.Computes) > 0 {
|
||||||
dataAccessor := (&datacenter.DatacenterResource{}).GetAccessor(nil)
|
dataAccessor := (&compute.ComputeResource{}).GetAccessor(nil)
|
||||||
for _, id := range workflow.Datacenters {
|
for _, id := range workflow.Computes {
|
||||||
d, _, e := dataAccessor.LoadOne(id)
|
d, _, e := dataAccessor.LoadOne(id)
|
||||||
if e == nil {
|
if e == nil {
|
||||||
workflow.DatacenterResources = append(workflow.DatacenterResources, d.(*datacenter.DatacenterResource))
|
workflow.ComputeResources = append(workflow.ComputeResources, d.(*compute.ComputeResource))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -200,26 +204,28 @@ func (wfa *workspaceMongoAccessor) Search(filters *dbs.Filters, search string) (
|
|||||||
/*
|
/*
|
||||||
This function is used to share the workspace with the peers
|
This function is used to share the workspace with the peers
|
||||||
*/
|
*/
|
||||||
func (wfa *workspaceMongoAccessor) share(realData *Workspace, delete bool, caller *tools.HTTPCaller) {
|
func (wfa *workspaceMongoAccessor) share(realData *Workspace, method tools.METHOD, caller *tools.HTTPCaller) {
|
||||||
if realData.Shared == "" {
|
if realData.Shared == "" || caller.Disabled {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
access := (&shallow_shared_workspace.ShallowSharedWorkspace{}).GetAccessor(nil)
|
access := (&shallow_collaborative_area.ShallowCollaborativeArea{}).GetAccessor(nil)
|
||||||
res, code, _ := access.LoadOne(realData.Shared)
|
res, code, _ := access.LoadOne(realData.Shared)
|
||||||
if code != 200 {
|
if code != 200 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var err error
|
var err error
|
||||||
paccess := &peer.Peer{}
|
paccess := &peer.Peer{}
|
||||||
for _, p := range res.(*shallow_shared_workspace.ShallowSharedWorkspace).Peers {
|
for _, p := range res.(*shallow_collaborative_area.ShallowCollaborativeArea).Peers {
|
||||||
paccess.UUID = p
|
paccess.UUID = p
|
||||||
if paccess.IsMySelf() { // If the peer is the current peer, never share because it will create a loop
|
if ok, _ := paccess.IsMySelf(); ok { // If the peer is the current peer, never share because it will create a loop
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if delete { // If the workspace is deleted, share the deletion
|
if method == tools.DELETE { // If the workspace is deleted, share the deletion
|
||||||
_, err = paccess.LaunchPeerExecution(p, res.GetID(), utils.WORKSPACE, tools.DELETE, map[string]interface{}{}, caller)
|
history := NewHistory()
|
||||||
|
history.StoreOne(history.MapFromWorkspace(res.(*Workspace)))
|
||||||
|
_, err = paccess.LaunchPeerExecution(p, res.GetID(), tools.WORKSPACE, tools.DELETE, map[string]interface{}{}, caller)
|
||||||
} else { // If the workspace is updated, share the update
|
} else { // If the workspace is updated, share the update
|
||||||
_, err = paccess.LaunchPeerExecution(p, res.GetID(), utils.WORKSPACE, tools.PUT, res.Serialize(), caller)
|
_, err = paccess.LaunchPeerExecution(p, res.GetID(), tools.WORKSPACE, tools.PUT, res.Serialize(), caller)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -1,30 +0,0 @@
|
|||||||
package static
|
|
||||||
|
|
||||||
/*
|
|
||||||
This package contains static data for the peer model
|
|
||||||
It's used to test the peer model
|
|
||||||
Temporary version, will be removed in the future and replaced with a more dynamic solution
|
|
||||||
to generate the data
|
|
||||||
*/
|
|
||||||
|
|
||||||
// GetMyLocalBsonPeer returns a tuple with the peer ID and the peer data in BSON format
|
|
||||||
func GetMyLocalBsonPeer() (string, map[string]interface{}) {
|
|
||||||
return "6fd0134c-fefc-427e-94c2-e01365fc5fb0", map[string]interface{}{
|
|
||||||
"abstractobject": map[string]interface{}{
|
|
||||||
"id": "6fd0134c-fefc-427e-94c2-e01365fc5fb0",
|
|
||||||
"name": "local_peer",
|
|
||||||
},
|
|
||||||
"url": "http://localhost",
|
|
||||||
"public_key": "public_key_lulz",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetMyLocalJsonPeer returns a tuple with the peer ID and the peer data in JSON format
|
|
||||||
func GetMyLocalJsonPeer() (string, map[string]interface{}) {
|
|
||||||
return "6fd0134c-fefc-427e-94c2-e01365fc5fb0", map[string]interface{}{
|
|
||||||
"id": "6fd0134c-fefc-427e-94c2-e01365fc5fb0",
|
|
||||||
"name": "local_peer",
|
|
||||||
"url": "http://localhost",
|
|
||||||
"public_key": "public_key_lulz",
|
|
||||||
}
|
|
||||||
}
|
|
BIN
swagger/favicon-16x16.png
Normal file
BIN
swagger/favicon-16x16.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 665 B |
BIN
swagger/favicon-32x32.png
Normal file
BIN
swagger/favicon-32x32.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 628 B |
60
swagger/index.html
Normal file
60
swagger/index.html
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
<!-- HTML for static distribution bundle build -->
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>Swagger UI</title>
|
||||||
|
<link rel="stylesheet" type="text/css" href="./swagger-ui.css" />
|
||||||
|
<link rel="icon" type="image/png" href="./favicon-32x32.png" sizes="32x32" />
|
||||||
|
<link rel="icon" type="image/png" href="./favicon-16x16.png" sizes="16x16" />
|
||||||
|
<style>
|
||||||
|
html
|
||||||
|
{
|
||||||
|
box-sizing: border-box;
|
||||||
|
overflow: -moz-scrollbars-vertical;
|
||||||
|
overflow-y: scroll;
|
||||||
|
}
|
||||||
|
|
||||||
|
*,
|
||||||
|
*:before,
|
||||||
|
*:after
|
||||||
|
{
|
||||||
|
box-sizing: inherit;
|
||||||
|
}
|
||||||
|
|
||||||
|
body
|
||||||
|
{
|
||||||
|
margin:0;
|
||||||
|
background: #fafafa;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<div id="swagger-ui"></div>
|
||||||
|
|
||||||
|
<script src="./swagger-ui-bundle.js" charset="UTF-8"> </script>
|
||||||
|
<script src="./swagger-ui-standalone-preset.js" charset="UTF-8"> </script>
|
||||||
|
<script>
|
||||||
|
window.onload = function() {
|
||||||
|
// Begin Swagger UI call region
|
||||||
|
const ui = SwaggerUIBundle({
|
||||||
|
url: "https://petstore.swagger.io/v2/swagger.json",
|
||||||
|
dom_id: '#swagger-ui',
|
||||||
|
deepLinking: true,
|
||||||
|
presets: [
|
||||||
|
SwaggerUIBundle.presets.apis,
|
||||||
|
SwaggerUIStandalonePreset
|
||||||
|
],
|
||||||
|
plugins: [
|
||||||
|
SwaggerUIBundle.plugins.DownloadUrl
|
||||||
|
],
|
||||||
|
layout: "StandaloneLayout"
|
||||||
|
});
|
||||||
|
// End Swagger UI call region
|
||||||
|
|
||||||
|
window.ui = ui;
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
79
swagger/oauth2-redirect.html
Normal file
79
swagger/oauth2-redirect.html
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="en-US">
|
||||||
|
<head>
|
||||||
|
<title>Swagger UI: OAuth2 Redirect</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<script>
|
||||||
|
'use strict';
|
||||||
|
function run () {
|
||||||
|
var oauth2 = window.opener.swaggerUIRedirectOauth2;
|
||||||
|
var sentState = oauth2.state;
|
||||||
|
var redirectUrl = oauth2.redirectUrl;
|
||||||
|
var isValid, qp, arr;
|
||||||
|
|
||||||
|
if (/code|token|error/.test(window.location.hash)) {
|
||||||
|
qp = window.location.hash.substring(1);
|
||||||
|
} else {
|
||||||
|
qp = location.search.substring(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
arr = qp.split("&");
|
||||||
|
arr.forEach(function (v,i,_arr) { _arr[i] = '"' + v.replace('=', '":"') + '"';});
|
||||||
|
qp = qp ? JSON.parse('{' + arr.join() + '}',
|
||||||
|
function (key, value) {
|
||||||
|
return key === "" ? value : decodeURIComponent(value);
|
||||||
|
}
|
||||||
|
) : {};
|
||||||
|
|
||||||
|
isValid = qp.state === sentState;
|
||||||
|
|
||||||
|
if ((
|
||||||
|
oauth2.auth.schema.get("flow") === "accessCode" ||
|
||||||
|
oauth2.auth.schema.get("flow") === "authorizationCode" ||
|
||||||
|
oauth2.auth.schema.get("flow") === "authorization_code"
|
||||||
|
) && !oauth2.auth.code) {
|
||||||
|
if (!isValid) {
|
||||||
|
oauth2.errCb({
|
||||||
|
authId: oauth2.auth.name,
|
||||||
|
source: "auth",
|
||||||
|
level: "warning",
|
||||||
|
message: "Authorization may be unsafe, passed state was changed in server Passed state wasn't returned from auth server"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (qp.code) {
|
||||||
|
delete oauth2.state;
|
||||||
|
oauth2.auth.code = qp.code;
|
||||||
|
oauth2.callback({auth: oauth2.auth, redirectUrl: redirectUrl});
|
||||||
|
} else {
|
||||||
|
let oauthErrorMsg;
|
||||||
|
if (qp.error) {
|
||||||
|
oauthErrorMsg = "["+qp.error+"]: " +
|
||||||
|
(qp.error_description ? qp.error_description+ ". " : "no accessCode received from the server. ") +
|
||||||
|
(qp.error_uri ? "More info: "+qp.error_uri : "");
|
||||||
|
}
|
||||||
|
|
||||||
|
oauth2.errCb({
|
||||||
|
authId: oauth2.auth.name,
|
||||||
|
source: "auth",
|
||||||
|
level: "error",
|
||||||
|
message: oauthErrorMsg || "[Authorization failed]: no accessCode received from the server"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
oauth2.callback({auth: oauth2.auth, token: qp, isValid: isValid, redirectUrl: redirectUrl});
|
||||||
|
}
|
||||||
|
window.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (document.readyState !== 'loading') {
|
||||||
|
run();
|
||||||
|
} else {
|
||||||
|
document.addEventListener('DOMContentLoaded', function () {
|
||||||
|
run();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
3
swagger/swagger-ui-bundle.js
Normal file
3
swagger/swagger-ui-bundle.js
Normal file
File diff suppressed because one or more lines are too long
1
swagger/swagger-ui-bundle.js.map
Normal file
1
swagger/swagger-ui-bundle.js.map
Normal file
File diff suppressed because one or more lines are too long
2
swagger/swagger-ui-es-bundle-core.js
Normal file
2
swagger/swagger-ui-es-bundle-core.js
Normal file
File diff suppressed because one or more lines are too long
3
swagger/swagger-ui-es-bundle.js
Normal file
3
swagger/swagger-ui-es-bundle.js
Normal file
File diff suppressed because one or more lines are too long
3
swagger/swagger-ui-standalone-preset.js
Normal file
3
swagger/swagger-ui-standalone-preset.js
Normal file
File diff suppressed because one or more lines are too long
1
swagger/swagger-ui-standalone-preset.js.map
Normal file
1
swagger/swagger-ui-standalone-preset.js.map
Normal file
File diff suppressed because one or more lines are too long
4
swagger/swagger-ui.css
Normal file
4
swagger/swagger-ui.css
Normal file
File diff suppressed because one or more lines are too long
1
swagger/swagger-ui.css.map
Normal file
1
swagger/swagger-ui.css.map
Normal file
File diff suppressed because one or more lines are too long
2
swagger/swagger-ui.js
Normal file
2
swagger/swagger-ui.js
Normal file
File diff suppressed because one or more lines are too long
1
swagger/swagger-ui.js.map
Normal file
1
swagger/swagger-ui.js.map
Normal file
File diff suppressed because one or more lines are too long
51
tools/api.go
51
tools/api.go
@ -3,9 +3,12 @@ package tools
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"cloud.o-forge.io/core/oc-lib/config"
|
"cloud.o-forge.io/core/oc-lib/config"
|
||||||
"cloud.o-forge.io/core/oc-lib/dbs/mongo"
|
"cloud.o-forge.io/core/oc-lib/dbs/mongo"
|
||||||
|
beego "github.com/beego/beego/v2/server/web"
|
||||||
)
|
)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -49,6 +52,16 @@ func (s State) String() string {
|
|||||||
|
|
||||||
type API struct{}
|
type API struct{}
|
||||||
|
|
||||||
|
func (a *API) Discovered(infos []*beego.ControllerInfo) {
|
||||||
|
respondToDiscovery := func(m map[string]interface{}) {
|
||||||
|
if len(m) == 0 {
|
||||||
|
a.SubscribeRouter(infos)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
a.ListenRouter(respondToDiscovery)
|
||||||
|
a.SubscribeRouter(infos)
|
||||||
|
}
|
||||||
|
|
||||||
// GetState returns the state of the API
|
// GetState returns the state of the API
|
||||||
func (a *API) GetState() (State, int, error) {
|
func (a *API) GetState() (State, int, error) {
|
||||||
// Check if the database is up
|
// Check if the database is up
|
||||||
@ -70,12 +83,34 @@ func (a *API) GetState() (State, int, error) {
|
|||||||
return ALIVE, 200, nil // If everything is up, return alive
|
return ALIVE, 200, nil // If everything is up, return alive
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *API) ListenRouter(exec func(msg map[string]interface{})) {
|
||||||
|
go NewNATSCaller().ListenNats(DISCOVERY.GenerateKey("api"), exec)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *API) SubscribeRouter(infos []*beego.ControllerInfo) {
|
||||||
|
nats := NewNATSCaller()
|
||||||
|
discovery := map[string]interface{}{}
|
||||||
|
for _, info := range infos {
|
||||||
|
methods := []string{}
|
||||||
|
for k, v := range info.GetMethod() {
|
||||||
|
if strings.Contains(strings.ToLower(v), "internal") {
|
||||||
|
methods = append(methods, "INTERNAL"+k)
|
||||||
|
} else {
|
||||||
|
methods = append(methods, k)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
path := strings.ReplaceAll(info.GetPattern(), "/oc/", "/"+strings.ReplaceAll(config.GetAppName(), "oc-", ""))
|
||||||
|
discovery[path] = methods
|
||||||
|
}
|
||||||
|
nats.SetNATSPub("api", DISCOVERY, discovery)
|
||||||
|
}
|
||||||
|
|
||||||
// CheckRemotePeer checks the state of a remote peer
|
// CheckRemotePeer checks the state of a remote peer
|
||||||
func (a *API) CheckRemotePeer(url string) (State, map[string]int) {
|
func (a *API) CheckRemotePeer(url string) (State, map[string]int) {
|
||||||
// Check if the database is up
|
// Check if the database is up
|
||||||
caller := NewHTTPCaller(map[string]map[METHOD]string{}) // Create a new http caller
|
caller := NewHTTPCaller(map[DataType]map[METHOD]string{}) // Create a new http caller
|
||||||
var resp APIStatusResponse
|
var resp APIStatusResponse
|
||||||
b, err := caller.CallPost(url, "/status", map[string]interface{}{}) // Call the status endpoint of the peer
|
b, err := caller.CallPost(url, "", map[string]interface{}{}) // Call the status endpoint of the peer
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return DEAD, map[string]int{} // If the peer is not reachable, return dead
|
return DEAD, map[string]int{} // If the peer is not reachable, return dead
|
||||||
}
|
}
|
||||||
@ -91,27 +126,29 @@ func (a *API) CheckRemotePeer(url string) (State, map[string]int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CheckRemoteAPIs checks the state of remote APIs from your proper OC
|
// CheckRemoteAPIs checks the state of remote APIs from your proper OC
|
||||||
func (a *API) CheckRemoteAPIs(urls map[string]string) (State, map[string]string, error) {
|
func (a *API) CheckRemoteAPIs(apis []DataType) (State, map[string]string, error) {
|
||||||
// Check if the database is up
|
// Check if the database is up
|
||||||
new := map[string]string{}
|
new := map[string]string{}
|
||||||
caller := NewHTTPCaller(map[string]map[METHOD]string{}) // Create a new http caller
|
caller := NewHTTPCaller(map[DataType]map[METHOD]string{}) // Create a new http caller
|
||||||
code := 0
|
code := 0
|
||||||
e := ""
|
e := ""
|
||||||
state := ALIVE
|
state := ALIVE
|
||||||
reachable := false
|
reachable := false
|
||||||
for appName, url := range urls { // Check the state of each remote API in the list
|
for _, api := range apis { // Check the state of each remote API in the list
|
||||||
var resp APIStatusResponse
|
var resp APIStatusResponse
|
||||||
b, err := caller.CallGet(url, "/version/status") // Call the status endpoint of the remote API (standard OC status endpoint)
|
b, err := caller.CallGet("http://"+api.API()+":8080", "/oc/version/status") // Call the status endpoint of the remote API (standard OC status endpoint)
|
||||||
|
fmt.Println(err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
state = REDUCED_SERVICE // If a remote API is not reachable, return reduced service
|
state = REDUCED_SERVICE // If a remote API is not reachable, return reduced service
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
json.Unmarshal(b, &resp)
|
json.Unmarshal(b, &resp)
|
||||||
|
fmt.Println(string(b))
|
||||||
if resp.Data == nil { //
|
if resp.Data == nil { //
|
||||||
state = REDUCED_SERVICE // If the response is empty, return reduced service
|
state = REDUCED_SERVICE // If the response is empty, return reduced service
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
new[appName] = resp.Data.State
|
new[api.String()] = resp.Data.State
|
||||||
if resp.Data.Code > code {
|
if resp.Data.Code > code {
|
||||||
code = resp.Data.Code
|
code = resp.Data.Code
|
||||||
e += resp.Error
|
e += resp.Error
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package utils
|
package tools
|
||||||
|
|
||||||
type DataType int
|
type DataType int
|
||||||
|
|
||||||
@ -8,34 +8,46 @@ const (
|
|||||||
DATA_RESOURCE
|
DATA_RESOURCE
|
||||||
PROCESSING_RESOURCE
|
PROCESSING_RESOURCE
|
||||||
STORAGE_RESOURCE
|
STORAGE_RESOURCE
|
||||||
DATACENTER_RESOURCE
|
COMPUTE_RESOURCE
|
||||||
WORKFLOW_RESOURCE
|
WORKFLOW_RESOURCE
|
||||||
WORKFLOW
|
WORKFLOW
|
||||||
WORKFLOW_EXECUTION
|
WORKFLOW_EXECUTION
|
||||||
WORKSPACE
|
WORKSPACE
|
||||||
RESOURCE_MODEL
|
RESOURCE_MODEL
|
||||||
PEER
|
PEER
|
||||||
SHARED_WORKSPACE
|
COLLABORATIVE_AREA
|
||||||
RULE
|
RULE
|
||||||
BOOKING
|
BOOKING
|
||||||
|
WORKFLOW_HISTORY
|
||||||
|
WORKSPACE_HISTORY
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var NOAPI = ""
|
||||||
|
var CATALOGAPI = "oc-catalog"
|
||||||
|
var SHAREDAPI = "oc-shared"
|
||||||
|
var WORKFLOWAPI = "oc-workflow"
|
||||||
|
var WORKSPACEAPI = "oc-workspace"
|
||||||
|
var PEERSAPI = "oc-peer"
|
||||||
|
var DATACENTERAPI = "oc-datacenter"
|
||||||
|
|
||||||
// Bind the standard API name to the data type
|
// Bind the standard API name to the data type
|
||||||
var DefaultAPI = [...]string{
|
var DefaultAPI = [...]string{
|
||||||
"",
|
NOAPI,
|
||||||
"oc-catalog",
|
CATALOGAPI,
|
||||||
"oc-catalog",
|
CATALOGAPI,
|
||||||
"oc-catalog",
|
CATALOGAPI,
|
||||||
"oc-catalog",
|
CATALOGAPI,
|
||||||
"oc-catalog",
|
CATALOGAPI,
|
||||||
"oc-workflow",
|
WORKFLOWAPI,
|
||||||
"",
|
NOAPI,
|
||||||
"oc-workspace",
|
WORKSPACEAPI,
|
||||||
"",
|
CATALOGAPI,
|
||||||
"oc-peers",
|
PEERSAPI,
|
||||||
"oc-shared",
|
SHAREDAPI,
|
||||||
"oc-shared",
|
SHAREDAPI,
|
||||||
"oc-datacenter",
|
DATACENTERAPI,
|
||||||
|
NOAPI,
|
||||||
|
NOAPI,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bind the standard data name to the data type
|
// Bind the standard data name to the data type
|
||||||
@ -44,7 +56,7 @@ var Str = [...]string{
|
|||||||
"data_resource",
|
"data_resource",
|
||||||
"processing_resource",
|
"processing_resource",
|
||||||
"storage_resource",
|
"storage_resource",
|
||||||
"datacenter_resource",
|
"compute_resource",
|
||||||
"workflow_resource",
|
"workflow_resource",
|
||||||
"workflow",
|
"workflow",
|
||||||
"workflow_execution",
|
"workflow_execution",
|
||||||
@ -54,6 +66,8 @@ var Str = [...]string{
|
|||||||
"shared_workspace",
|
"shared_workspace",
|
||||||
"rule",
|
"rule",
|
||||||
"booking",
|
"booking",
|
||||||
|
"workflow_history",
|
||||||
|
"workspace_history",
|
||||||
}
|
}
|
||||||
|
|
||||||
func FromInt(i int) string {
|
func FromInt(i int) string {
|
@ -5,6 +5,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"cloud.o-forge.io/core/oc-lib/config"
|
"cloud.o-forge.io/core/oc-lib/config"
|
||||||
|
"cloud.o-forge.io/core/oc-lib/logs"
|
||||||
"github.com/nats-io/nats.go"
|
"github.com/nats-io/nats.go"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -14,6 +15,7 @@ type NATSMethod int
|
|||||||
const (
|
const (
|
||||||
REMOVE NATSMethod = iota
|
REMOVE NATSMethod = iota
|
||||||
CREATE
|
CREATE
|
||||||
|
DISCOVERY
|
||||||
)
|
)
|
||||||
|
|
||||||
// NameToMethod returns the NATSMethod enum value from a string
|
// NameToMethod returns the NATSMethod enum value from a string
|
||||||
@ -43,6 +45,33 @@ func NewNATSCaller() *natsCaller {
|
|||||||
return &natsCaller{}
|
return &natsCaller{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// on workflows' scheduling. Messages must contain
|
||||||
|
// workflow execution ID, to allow retrieval of execution infos
|
||||||
|
func (s *natsCaller) ListenNats(chanName string, exec func(msg map[string]interface{})) {
|
||||||
|
log := logs.GetLogger()
|
||||||
|
if config.GetConfig().NATSUrl == "" {
|
||||||
|
log.Error().Msg(" -> NATS_SERVER is not set")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
nc, err := nats.Connect(config.GetConfig().NATSUrl)
|
||||||
|
if err != nil {
|
||||||
|
log.Error().Msg(" -> Could not reach NATS server : " + err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ch := make(chan *nats.Msg, 64)
|
||||||
|
subs, err := nc.ChanSubscribe(chanName, ch)
|
||||||
|
if err != nil {
|
||||||
|
log.Error().Msg("Error listening to NATS : " + err.Error())
|
||||||
|
}
|
||||||
|
defer subs.Unsubscribe()
|
||||||
|
|
||||||
|
for msg := range ch {
|
||||||
|
map_mess := map[string]interface{}{}
|
||||||
|
json.Unmarshal(msg.Data, &map_mess)
|
||||||
|
exec(map_mess)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// SetNATSPub sets a message to the NATS server
|
// SetNATSPub sets a message to the NATS server
|
||||||
func (o *natsCaller) SetNATSPub(dataName string, method NATSMethod, data interface{}) string {
|
func (o *natsCaller) SetNATSPub(dataName string, method NATSMethod, data interface{}) string {
|
||||||
if config.GetConfig().NATSUrl == "" {
|
if config.GetConfig().NATSUrl == "" {
|
||||||
|
@ -5,6 +5,8 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/url"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// HTTP Method Enum defines the different methods that can be used to interact with the HTTP server
|
// HTTP Method Enum defines the different methods that can be used to interact with the HTTP server
|
||||||
@ -15,11 +17,16 @@ const (
|
|||||||
PUT
|
PUT
|
||||||
POST
|
POST
|
||||||
DELETE
|
DELETE
|
||||||
|
|
||||||
|
STRICT_INTERNAL_GET
|
||||||
|
STRICT_INTERNAL_PUT
|
||||||
|
STRICT_INTERNAL_POST
|
||||||
|
STRICT_INTERNAL_DELETE
|
||||||
)
|
)
|
||||||
|
|
||||||
// String returns the string of the enum
|
// String returns the string of the enum
|
||||||
func (m METHOD) String() string {
|
func (m METHOD) String() string {
|
||||||
return [...]string{"GET", "PUT", "POST", "DELETE"}[m]
|
return [...]string{"GET", "PUT", "POST", "DELETE", "INTERNALGET", "INTERNALPUT", "INTERNALPOST", "INTERNALDELETE"}[m]
|
||||||
}
|
}
|
||||||
|
|
||||||
// EnumIndex returns the index of the enum
|
// EnumIndex returns the index of the enum
|
||||||
@ -29,7 +36,8 @@ func (m METHOD) EnumIndex() int {
|
|||||||
|
|
||||||
// ToMethod returns the method from a string
|
// ToMethod returns the method from a string
|
||||||
func ToMethod(str string) METHOD {
|
func ToMethod(str string) METHOD {
|
||||||
for _, s := range []METHOD{GET, PUT, POST, DELETE} {
|
for _, s := range []METHOD{GET, PUT, POST, DELETE,
|
||||||
|
STRICT_INTERNAL_GET, STRICT_INTERNAL_PUT, STRICT_INTERNAL_POST, STRICT_INTERNAL_DELETE} {
|
||||||
if s.String() == str {
|
if s.String() == str {
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
@ -40,19 +48,29 @@ func ToMethod(str string) METHOD {
|
|||||||
var HTTPCallerInstance = &HTTPCaller{} // Singleton instance of the HTTPCaller
|
var HTTPCallerInstance = &HTTPCaller{} // Singleton instance of the HTTPCaller
|
||||||
|
|
||||||
type HTTPCaller struct {
|
type HTTPCaller struct {
|
||||||
URLS map[string]map[METHOD]string // Map of the different methods and their urls
|
URLS map[DataType]map[METHOD]string // Map of the different methods and their urls
|
||||||
|
Disabled bool // Disabled flag
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewHTTPCaller creates a new instance of the HTTP Caller
|
// NewHTTPCaller creates a new instance of the HTTP Caller
|
||||||
func NewHTTPCaller(urls map[string]map[METHOD]string) *HTTPCaller {
|
func NewHTTPCaller(urls map[DataType]map[METHOD]string) *HTTPCaller {
|
||||||
return &HTTPCaller{
|
return &HTTPCaller{
|
||||||
URLS: urls, // Set the urls defined in the config & based on the data name type & method
|
URLS: urls, // Set the urls defined in the config & based on the data name type & method
|
||||||
|
Disabled: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// CallGet calls the GET method on the HTTP server
|
// CallGet calls the GET method on the HTTP server
|
||||||
func (caller *HTTPCaller) CallGet(url string, subpath string) ([]byte, error) {
|
func (caller *HTTPCaller) CallGet(url string, subpath string, types ...string) ([]byte, error) {
|
||||||
resp, err := http.Get(url + subpath)
|
req, err := http.NewRequest(http.MethodGet, url+subpath, bytes.NewBuffer([]byte("")))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
for _, t := range types {
|
||||||
|
req.Header.Set("Content-Type", t)
|
||||||
|
}
|
||||||
|
client := &http.Client{}
|
||||||
|
resp, err := client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -63,7 +81,7 @@ func (caller *HTTPCaller) CallGet(url string, subpath string) ([]byte, error) {
|
|||||||
// CallPut calls the DELETE method on the HTTP server
|
// CallPut calls the DELETE method on the HTTP server
|
||||||
func (caller *HTTPCaller) CallDelete(url string, subpath string) ([]byte, error) {
|
func (caller *HTTPCaller) CallDelete(url string, subpath string) ([]byte, error) {
|
||||||
resp, err := http.NewRequest("DELETE", url+subpath, nil)
|
resp, err := http.NewRequest("DELETE", url+subpath, nil)
|
||||||
if err != nil {
|
if err != nil || resp == nil || resp.Body == nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
@ -71,10 +89,32 @@ func (caller *HTTPCaller) CallDelete(url string, subpath string) ([]byte, error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CallPost calls the POST method on the HTTP server
|
// CallPost calls the POST method on the HTTP server
|
||||||
func (caller *HTTPCaller) CallPost(url string, subpath string, body map[string]interface{}) ([]byte, error) {
|
func (caller *HTTPCaller) CallPost(url string, subpath string, body map[string]interface{}, types ...string) ([]byte, error) {
|
||||||
postBody, _ := json.Marshal(body)
|
postBody, _ := json.Marshal(body)
|
||||||
responseBody := bytes.NewBuffer(postBody)
|
responseBody := bytes.NewBuffer(postBody)
|
||||||
resp, err := http.Post(url+subpath, "application/json", responseBody)
|
contentType := "application/json"
|
||||||
|
if len(types) > 0 {
|
||||||
|
contentType = types[0]
|
||||||
|
}
|
||||||
|
resp, err := http.Post(url+subpath, contentType, responseBody)
|
||||||
|
if err != nil || resp == nil || resp.Body == nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
return io.ReadAll(resp.Body)
|
||||||
|
}
|
||||||
|
|
||||||
|
// CallPost calls the POST method on the HTTP server
|
||||||
|
func (caller *HTTPCaller) CallPut(url string, subpath string, body map[string]interface{}) ([]byte, error) {
|
||||||
|
postBody, _ := json.Marshal(body)
|
||||||
|
responseBody := bytes.NewBuffer(postBody)
|
||||||
|
req, err := http.NewRequest(http.MethodPut, url+subpath, responseBody)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
req.Header.Set("Content-Type", "application/json")
|
||||||
|
client := &http.Client{}
|
||||||
|
resp, err := client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -82,4 +122,40 @@ func (caller *HTTPCaller) CallPost(url string, subpath string, body map[string]i
|
|||||||
return io.ReadAll(resp.Body)
|
return io.ReadAll(resp.Body)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NO PUT IN HERE TO DANGEROUS TO USE ON A REMOTE SERVER, MAYBE NEEDED IN THE FUTURE
|
// CallRaw calls the Raw method on the HTTP server
|
||||||
|
func (caller *HTTPCaller) CallRaw(method string, url string, subpath string,
|
||||||
|
body map[string]interface{}, content_type string, fakeTLSTermination bool, cookies ...*http.Cookie) (*http.Response, error) {
|
||||||
|
postBody, _ := json.Marshal(body)
|
||||||
|
responseBody := bytes.NewBuffer(postBody)
|
||||||
|
req, err := http.NewRequest(method, url+subpath, responseBody)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
req.Header.Set("Content-Type", content_type)
|
||||||
|
if fakeTLSTermination {
|
||||||
|
req.Header.Add("X-Forwarded-Proto", "https")
|
||||||
|
}
|
||||||
|
for _, c := range cookies {
|
||||||
|
req.AddCookie(c)
|
||||||
|
}
|
||||||
|
client := &http.Client{}
|
||||||
|
return client.Do(req)
|
||||||
|
}
|
||||||
|
|
||||||
|
// CallRaw calls the Raw method on the HTTP server
|
||||||
|
func (caller *HTTPCaller) CallForm(method string, url string, subpath string,
|
||||||
|
body url.Values, content_type string, fakeTLSTermination bool, cookies ...*http.Cookie) (*http.Response, error) {
|
||||||
|
req, err := http.NewRequest(method, url+subpath, strings.NewReader(body.Encode()))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
req.Header.Set("Content-Type", content_type)
|
||||||
|
if fakeTLSTermination {
|
||||||
|
req.Header.Add("X-Forwarded-Proto", "https")
|
||||||
|
}
|
||||||
|
for _, c := range cookies {
|
||||||
|
req.AddCookie(c)
|
||||||
|
}
|
||||||
|
client := &http.Client{}
|
||||||
|
return client.Do(req)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user