Compare commits
No commits in common. "master" and "chart" have entirely different histories.
660
LICENSE.md
660
LICENSE.md
@ -1,660 +0,0 @@
|
||||
# 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,6 +8,7 @@ import (
|
||||
|
||||
"cloud.o-forge.io/core/oc-lib/dbs"
|
||||
"cloud.o-forge.io/core/oc-lib/logs"
|
||||
"cloud.o-forge.io/core/oc-lib/static"
|
||||
"github.com/rs/zerolog"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
@ -131,6 +132,10 @@ func (m *MongoDB) prepareDB(list_collection []string, config MongoConf) {
|
||||
new_collection := mngoDB.Collection(collection_name)
|
||||
if _, exists := collectionMap[collection_name]; !exists {
|
||||
m.createCollection(collection_name, new_collection)
|
||||
if collection_name == "peer" {
|
||||
id, p := static.GetMyLocalBsonPeer()
|
||||
m.StoreOne(p, id, collection_name)
|
||||
}
|
||||
} else {
|
||||
CollectionMap[collection_name] = new_collection
|
||||
}
|
||||
@ -214,7 +219,7 @@ func (m *MongoDB) UpdateMultiple(set interface{}, filter map[string]interface{},
|
||||
f = append(f, bson.E{Key: k, Value: v})
|
||||
}
|
||||
targetDBCollection := CollectionMap[collection_name]
|
||||
MngoCtx, cancel = context.WithTimeout(context.Background(), 50*time.Second)
|
||||
MngoCtx, cancel = context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
res, err := targetDBCollection.UpdateMany(MngoCtx, f, dbs.InputToBson(doc, true))
|
||||
if err != nil {
|
||||
@ -233,7 +238,7 @@ func (m *MongoDB) UpdateOne(set interface{}, id string, collection_name string)
|
||||
bson.Unmarshal(b, &doc)
|
||||
filter := bson.M{"_id": id}
|
||||
targetDBCollection := CollectionMap[collection_name]
|
||||
MngoCtx, cancel = context.WithTimeout(context.Background(), 50*time.Second)
|
||||
MngoCtx, cancel = context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
_, err := targetDBCollection.UpdateOne(MngoCtx, filter, dbs.InputToBson(doc, true))
|
||||
if err != nil {
|
||||
@ -270,6 +275,7 @@ func (m *MongoDB) LoadOne(id string, collection_name string) (*mongo.SingleResul
|
||||
}
|
||||
filter := bson.M{"_id": id}
|
||||
targetDBCollection := CollectionMap[collection_name]
|
||||
|
||||
MngoCtx, cancel = context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
|
||||
|
@ -19,7 +19,7 @@ func init() {
|
||||
{Key: "example", Value: "text"}},
|
||||
})
|
||||
|
||||
IndexesMap["compute"] = append(IndexesMap["compute"], mongo.IndexModel{Keys: bson.D{
|
||||
IndexesMap["datacenter"] = append(IndexesMap["datacenter"], mongo.IndexModel{Keys: bson.D{
|
||||
{Key: "description", Value: "text"},
|
||||
{Key: "example", Value: "text"},
|
||||
{Key: "owner", Value: "text"}},
|
||||
|
147
entrypoint.go
147
entrypoint.go
@ -3,7 +3,6 @@ package oclib
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"runtime/debug"
|
||||
|
||||
@ -12,12 +11,10 @@ import (
|
||||
"cloud.o-forge.io/core/oc-lib/dbs/mongo"
|
||||
"cloud.o-forge.io/core/oc-lib/logs"
|
||||
"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/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/datacenter"
|
||||
"cloud.o-forge.io/core/oc-lib/models/resources/processing"
|
||||
"cloud.o-forge.io/core/oc-lib/models/resources/storage"
|
||||
w "cloud.o-forge.io/core/oc-lib/models/resources/workflow"
|
||||
@ -25,9 +22,9 @@ import (
|
||||
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/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"
|
||||
beego "github.com/beego/beego/v2/server/web"
|
||||
"github.com/beego/beego/v2/server/web/context"
|
||||
"github.com/goraz/onion"
|
||||
"github.com/rs/zerolog"
|
||||
)
|
||||
@ -39,28 +36,28 @@ type LibDataEnum int
|
||||
// init accessible constant to retrieve data from the database
|
||||
const (
|
||||
INVALID LibDataEnum = iota
|
||||
DATA_RESOURCE = tools.DATA_RESOURCE
|
||||
PROCESSING_RESOURCE = tools.PROCESSING_RESOURCE
|
||||
STORAGE_RESOURCE = tools.STORAGE_RESOURCE
|
||||
COMPUTE_RESOURCE = tools.COMPUTE_RESOURCE
|
||||
WORKFLOW_RESOURCE = tools.WORKFLOW_RESOURCE
|
||||
WORKFLOW = tools.WORKFLOW
|
||||
WORKSPACE = tools.WORKSPACE
|
||||
WORKFLOW_EXECUTION = tools.WORKFLOW_EXECUTION
|
||||
PEER = tools.PEER
|
||||
SHARED_WORKSPACE = tools.COLLABORATIVE_AREA
|
||||
RULE = tools.RULE
|
||||
BOOKING = tools.BOOKING
|
||||
DATA_RESOURCE = utils.DATA_RESOURCE
|
||||
PROCESSING_RESOURCE = utils.PROCESSING_RESOURCE
|
||||
STORAGE_RESOURCE = utils.STORAGE_RESOURCE
|
||||
DATACENTER_RESOURCE = utils.DATACENTER_RESOURCE
|
||||
WORKFLOW_RESOURCE = utils.WORKFLOW_RESOURCE
|
||||
WORKFLOW = utils.WORKFLOW
|
||||
WORKSPACE = utils.WORKSPACE
|
||||
WORKFLOW_EXECUTION = utils.WORKFLOW_EXECUTION
|
||||
PEER = utils.PEER
|
||||
SHARED_WORKSPACE = utils.SHARED_WORKSPACE
|
||||
RULE = utils.RULE
|
||||
BOOKING = utils.BOOKING
|
||||
)
|
||||
|
||||
// will turn into standards api hostnames
|
||||
func (d LibDataEnum) API() string {
|
||||
return tools.DefaultAPI[d]
|
||||
return utils.DefaultAPI[d]
|
||||
}
|
||||
|
||||
// will turn into standards name
|
||||
func (d LibDataEnum) String() string {
|
||||
return tools.Str[d]
|
||||
return utils.Str[d]
|
||||
}
|
||||
|
||||
// will turn into enum index
|
||||
@ -68,20 +65,6 @@ func (d LibDataEnum) EnumIndex() int {
|
||||
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
|
||||
type LibDataShallow struct {
|
||||
Data []utils.ShallowDBObject `bson:"data" json:"data"`
|
||||
@ -96,32 +79,29 @@ type LibData struct {
|
||||
Err string `bson:"error" json:"error"`
|
||||
}
|
||||
|
||||
func InitDaemon(appName string) {
|
||||
config.SetAppName(appName) // set the app name to the logger to define the main log chan
|
||||
// create a temporary console logger for init
|
||||
logs.SetLogger(logs.CreateLogger("main"))
|
||||
// Load the right config file
|
||||
o := GetConfLoader()
|
||||
// here is the singleton variable to store the paths that api will use
|
||||
var paths map[LibDataEnum]string = map[LibDataEnum]string{}
|
||||
|
||||
// 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"
|
||||
// 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) {
|
||||
InitDaemon(appName)
|
||||
api := &tools.API{}
|
||||
api.Discovered(beego.BeeApp.Handlers.GetAllControllerInfo())
|
||||
config.SetAppName(appName) // set the app name to the logger to define the main log chan
|
||||
// create a temporary console logger for init
|
||||
logs.SetLogger(logs.CreateLogger("main"))
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
@ -159,17 +139,17 @@ func SetConfig(mongoUrl string, database string, natsUrl string, lokiUrl string,
|
||||
Resource model is the model that will define the structure of the resources
|
||||
*/
|
||||
accessor := (&resource_model.ResourceModel{}).GetAccessor(nil)
|
||||
for _, model := range []string{tools.DATA_RESOURCE.String(), tools.PROCESSING_RESOURCE.String(), tools.STORAGE_RESOURCE.String(), tools.COMPUTE_RESOURCE.String(), tools.WORKFLOW_RESOURCE.String()} {
|
||||
for _, model := range []string{utils.DATA_RESOURCE.String(), utils.PROCESSING_RESOURCE.String(), utils.STORAGE_RESOURCE.String(), utils.DATACENTER_RESOURCE.String(), utils.WORKFLOW_RESOURCE.String()} {
|
||||
data, code, _ := accessor.Search(nil, model)
|
||||
if code == 404 || len(data) == 0 {
|
||||
refs := map[string]string{}
|
||||
m := map[string]resource_model.Model{}
|
||||
// TODO Specify the model for each resource
|
||||
// for now only processing is specified here (not an elegant way)
|
||||
if model == tools.DATA_RESOURCE.String() || model == tools.STORAGE_RESOURCE.String() {
|
||||
refs["path"] = "string"
|
||||
}
|
||||
if model == tools.PROCESSING_RESOURCE.String() {
|
||||
if model == utils.PROCESSING_RESOURCE.String() {
|
||||
m["image"] = resource_model.Model{
|
||||
Type: "string",
|
||||
ReadOnly: false,
|
||||
}
|
||||
m["command"] = resource_model.Model{
|
||||
Type: "string",
|
||||
ReadOnly: false,
|
||||
@ -178,21 +158,14 @@ func SetConfig(mongoUrl string, database string, natsUrl string, lokiUrl string,
|
||||
Type: "string",
|
||||
ReadOnly: false,
|
||||
}
|
||||
m["env"] = resource_model.Model{
|
||||
Type: "string",
|
||||
ReadOnly: false,
|
||||
}
|
||||
m["volumes"] = resource_model.Model{
|
||||
Type: "map[string]string",
|
||||
m["execute"] = resource_model.Model{
|
||||
Type: "map[int]map[string]string",
|
||||
ReadOnly: false,
|
||||
}
|
||||
}
|
||||
accessor.StoreOne(&resource_model.ResourceModel{
|
||||
ResourceType: model,
|
||||
VarRefs: refs,
|
||||
Model: map[string]map[string]resource_model.Model{
|
||||
"container": m,
|
||||
},
|
||||
Model: m,
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -421,72 +394,72 @@ func CopyOne(collection LibDataEnum, object map[string]interface{}, c ...*tools.
|
||||
// ================ CAST ========================= //
|
||||
|
||||
func (l *LibData) ToDataResource() *data.DataResource {
|
||||
if l.Data.GetAccessor(nil).GetType() == tools.DATA_RESOURCE.String() {
|
||||
if l.Data.GetAccessor(nil).GetType() == utils.DATA_RESOURCE.String() {
|
||||
return l.Data.(*data.DataResource)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (l *LibData) ToComputeResource() *compute.ComputeResource {
|
||||
if l.Data != nil && l.Data.GetAccessor(nil).GetType() == tools.COMPUTE_RESOURCE.String() {
|
||||
return l.Data.(*compute.ComputeResource)
|
||||
func (l *LibData) ToDatacenterResource() *datacenter.DatacenterResource {
|
||||
if l.Data != nil && l.Data.GetAccessor(nil).GetType() == utils.DATACENTER_RESOURCE.String() {
|
||||
return l.Data.(*datacenter.DatacenterResource)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (l *LibData) ToStorageResource() *storage.StorageResource {
|
||||
if l.Data.GetAccessor(nil).GetType() == tools.STORAGE_RESOURCE.String() {
|
||||
if l.Data.GetAccessor(nil).GetType() == utils.STORAGE_RESOURCE.String() {
|
||||
return l.Data.(*storage.StorageResource)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (l *LibData) ToProcessingResource() *processing.ProcessingResource {
|
||||
if l.Data.GetAccessor(nil).GetType() == tools.PROCESSING_RESOURCE.String() {
|
||||
if l.Data.GetAccessor(nil).GetType() == utils.PROCESSING_RESOURCE.String() {
|
||||
return l.Data.(*processing.ProcessingResource)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (l *LibData) ToWorkflowResource() *w.WorkflowResource {
|
||||
if l.Data.GetAccessor(nil).GetType() == tools.WORKFLOW_RESOURCE.String() {
|
||||
if l.Data.GetAccessor(nil).GetType() == utils.WORKFLOW_RESOURCE.String() {
|
||||
return l.Data.(*w.WorkflowResource)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (l *LibData) ToPeer() *peer.Peer {
|
||||
if l.Data.GetAccessor(nil).GetType() == tools.PEER.String() {
|
||||
if l.Data.GetAccessor(nil).GetType() == utils.PEER.String() {
|
||||
return l.Data.(*peer.Peer)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (l *LibData) ToWorkflow() *w2.Workflow {
|
||||
if l.Data.GetAccessor(nil).GetType() == tools.WORKFLOW.String() {
|
||||
if l.Data.GetAccessor(nil).GetType() == utils.WORKFLOW.String() {
|
||||
return l.Data.(*w2.Workflow)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (l *LibData) ToWorkspace() *workspace.Workspace {
|
||||
if l.Data.GetAccessor(nil).GetType() == tools.WORKSPACE.String() {
|
||||
if l.Data.GetAccessor(nil).GetType() == utils.WORKSPACE.String() {
|
||||
return l.Data.(*workspace.Workspace)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (l *LibData) ToCollaborativeArea() *collaborative_area.CollaborativeArea {
|
||||
if l.Data.GetAccessor(nil).GetType() == tools.COLLABORATIVE_AREA.String() {
|
||||
return l.Data.(*collaborative_area.CollaborativeArea)
|
||||
func (l *LibData) ToSharedWorkspace() *shared_workspace.SharedWorkspace {
|
||||
if l.Data.GetAccessor(nil).GetType() == utils.SHARED_WORKSPACE.String() {
|
||||
return l.Data.(*shared_workspace.SharedWorkspace)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (l *LibData) ToRule() *rule.Rule {
|
||||
if l.Data.GetAccessor(nil).GetType() == tools.COLLABORATIVE_AREA.String() {
|
||||
if l.Data.GetAccessor(nil).GetType() == utils.SHARED_WORKSPACE.String() {
|
||||
return l.Data.(*rule.Rule)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (l *LibData) ToWorkflowExecution() *workflow_execution.WorkflowExecution {
|
||||
if l.Data.GetAccessor(nil).GetType() == tools.WORKFLOW_EXECUTION.String() {
|
||||
if l.Data.GetAccessor(nil).GetType() == utils.WORKFLOW_EXECUTION.String() {
|
||||
return l.Data.(*workflow_execution.WorkflowExecution)
|
||||
}
|
||||
return nil
|
||||
|
14
go.mod
14
go.mod
@ -3,7 +3,6 @@ module cloud.o-forge.io/core/oc-lib
|
||||
go 1.22.0
|
||||
|
||||
require (
|
||||
github.com/beego/beego/v2 v2.3.1
|
||||
github.com/go-playground/validator/v10 v10.22.0
|
||||
github.com/google/uuid v1.6.0
|
||||
github.com/goraz/onion v0.1.3
|
||||
@ -26,25 +25,16 @@ 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/gabriel-vasile/mimetype v1.4.4 // indirect
|
||||
github.com/go-playground/locales v0.14.1 // indirect
|
||||
github.com/go-playground/universal-translator v0.18.1 // 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/kr/text v0.1.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/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // 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/scram v1.1.2 // indirect
|
||||
github.com/xdg-go/stringprep v1.0.4 // indirect
|
||||
@ -53,6 +43,6 @@ require (
|
||||
golang.org/x/net v0.27.0 // indirect
|
||||
golang.org/x/sync v0.7.0 // indirect
|
||||
golang.org/x/text v0.16.0 // indirect
|
||||
google.golang.org/protobuf v1.34.2 // indirect
|
||||
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
)
|
||||
|
34
go.sum
34
go.sum
@ -1,18 +1,10 @@
|
||||
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/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/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/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/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
|
||||
github.com/gabriel-vasile/mimetype v1.4.4 h1:QjV6pZ7/XZ7ryI2KuyeEDE8wnh7fHP9YnQy+R0LnH8I=
|
||||
@ -37,16 +29,12 @@ 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/goraz/onion v0.1.3 h1:KhyvbDA2b70gcz/d5izfwTiOH8SmrvV43AsVzpng3n0=
|
||||
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/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/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
|
||||
github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA=
|
||||
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/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
@ -60,8 +48,6 @@ 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/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||
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-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
|
||||
@ -74,28 +60,18 @@ 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/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw=
|
||||
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/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/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
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/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/zerolog v1.33.0 h1:1cU2KZkvPxNyfgEmhHAz/1A9Bz+llsdYzklWFzgp0r8=
|
||||
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/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=
|
||||
@ -158,11 +134,9 @@ 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.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
||||
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 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
||||
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=
|
||||
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
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.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
|
@ -17,10 +17,10 @@ import (
|
||||
*/
|
||||
type Booking struct {
|
||||
workflow_execution.WorkflowExecution // WorkflowExecution contains the workflow execution data
|
||||
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
|
||||
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
|
||||
}
|
||||
|
||||
// CheckBooking checks if a booking is possible on a specific compute resource
|
||||
// CheckBooking checks if a booking is possible on a specific datacenter resource
|
||||
func (wfa *Booking) CheckBooking(id string, start time.Time, end *time.Time) (bool, error) {
|
||||
// check if
|
||||
if end == nil {
|
||||
@ -30,8 +30,8 @@ func (wfa *Booking) CheckBooking(id string, start time.Time, end *time.Time) (bo
|
||||
e := *end
|
||||
accessor := wfa.GetAccessor(nil)
|
||||
res, code, err := accessor.Search(&dbs.Filters{
|
||||
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
|
||||
"compute_resource_id": {{Operator: dbs.EQUAL.String(), Value: id}},
|
||||
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
|
||||
"datacenter_resource_id": {{Operator: dbs.EQUAL.String(), Value: id}},
|
||||
"workflowexecution.state": {{Operator: dbs.EQUAL.String(), Value: workflow_execution.SCHEDULED.EnumIndex()}},
|
||||
"workflowexecution.execution_date": {
|
||||
{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 {
|
||||
data := New() // Create a new instance of the accessor
|
||||
data.Init(tools.BOOKING, caller) // Initialize the accessor with the BOOKING model type
|
||||
data.Init(utils.BOOKING, caller) // Initialize the accessor with the BOOKING model type
|
||||
return data
|
||||
}
|
||||
|
||||
|
@ -1,12 +1,9 @@
|
||||
package booking
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"cloud.o-forge.io/core/oc-lib/dbs"
|
||||
"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/workflow_execution"
|
||||
)
|
||||
|
||||
type bookingMongoAccessor struct {
|
||||
@ -45,14 +42,10 @@ func (wfa *bookingMongoAccessor) LoadOne(id string) (utils.DBObject, int, error)
|
||||
return nil, code, err
|
||||
}
|
||||
res_mongo.Decode(&workflow)
|
||||
if workflow.State == workflow_execution.SCHEDULED && time.Now().UTC().After(*workflow.ExecDate) {
|
||||
workflow.State = workflow_execution.FORGOTTEN
|
||||
wfa.GenericRawUpdateOne(&workflow, id, wfa)
|
||||
}
|
||||
return &workflow, 200, nil
|
||||
}
|
||||
|
||||
func (wfa *bookingMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int, error) {
|
||||
func (wfa bookingMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int, error) {
|
||||
objs := []utils.ShallowDBObject{}
|
||||
res_mongo, code, err := mongo.MONGOService.LoadAll(wfa.GetType())
|
||||
if err != nil {
|
||||
@ -64,10 +57,6 @@ func (wfa *bookingMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int, error)
|
||||
return nil, 404, err
|
||||
}
|
||||
for _, r := range results {
|
||||
if r.State == workflow_execution.SCHEDULED && time.Now().UTC().After(*r.ExecDate) {
|
||||
r.State = workflow_execution.FORGOTTEN
|
||||
wfa.GenericRawUpdateOne(&r, r.UUID, wfa)
|
||||
}
|
||||
objs = append(objs, &r.AbstractObject) // Warning only AbstractObject is returned
|
||||
}
|
||||
return objs, 200, nil
|
||||
@ -93,10 +82,6 @@ func (wfa *bookingMongoAccessor) Search(filters *dbs.Filters, search string) ([]
|
||||
return nil, 404, err
|
||||
}
|
||||
for _, r := range results {
|
||||
if r.State == workflow_execution.SCHEDULED && time.Now().UTC().After(*r.ExecDate) {
|
||||
r.State = workflow_execution.FORGOTTEN
|
||||
wfa.GenericRawUpdateOne(&r, r.UUID, wfa)
|
||||
}
|
||||
objs = append(objs, &r)
|
||||
}
|
||||
return objs, 200, nil
|
||||
|
@ -2,15 +2,12 @@ package models
|
||||
|
||||
import (
|
||||
"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/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/resource_model"
|
||||
d "cloud.o-forge.io/core/oc-lib/models/resources/data"
|
||||
"cloud.o-forge.io/core/oc-lib/models/resources/compute"
|
||||
dc "cloud.o-forge.io/core/oc-lib/models/resources/datacenter"
|
||||
p "cloud.o-forge.io/core/oc-lib/models/resources/processing"
|
||||
s "cloud.o-forge.io/core/oc-lib/models/resources/storage"
|
||||
w "cloud.o-forge.io/core/oc-lib/models/resources/workflow"
|
||||
@ -18,6 +15,8 @@ import (
|
||||
w2 "cloud.o-forge.io/core/oc-lib/models/workflow"
|
||||
"cloud.o-forge.io/core/oc-lib/models/workflow_execution"
|
||||
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"
|
||||
)
|
||||
|
||||
/*
|
||||
@ -25,30 +24,28 @@ This package contains the models used in the application
|
||||
It's used to create the models dynamically
|
||||
*/
|
||||
var models = map[string]func() utils.DBObject{
|
||||
tools.WORKFLOW_RESOURCE.String(): func() utils.DBObject { return &w.WorkflowResource{} },
|
||||
tools.DATA_RESOURCE.String(): func() utils.DBObject { return &d.DataResource{} },
|
||||
tools.COMPUTE_RESOURCE.String(): func() utils.DBObject { return &compute.ComputeResource{} },
|
||||
tools.STORAGE_RESOURCE.String(): func() utils.DBObject { return &s.StorageResource{} },
|
||||
tools.PROCESSING_RESOURCE.String(): func() utils.DBObject { return &p.ProcessingResource{} },
|
||||
tools.WORKFLOW.String(): func() utils.DBObject { return &w2.Workflow{} },
|
||||
tools.WORKFLOW_EXECUTION.String(): func() utils.DBObject { return &workflow_execution.WorkflowExecution{} },
|
||||
tools.WORKSPACE.String(): func() utils.DBObject { return &w3.Workspace{} },
|
||||
tools.RESOURCE_MODEL.String(): func() utils.DBObject { return &resource_model.ResourceModel{} },
|
||||
tools.PEER.String(): func() utils.DBObject { return &peer.Peer{} },
|
||||
tools.COLLABORATIVE_AREA.String(): func() utils.DBObject { return &collaborative_area.CollaborativeArea{} },
|
||||
tools.RULE.String(): func() utils.DBObject { return &rule.Rule{} },
|
||||
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{} },
|
||||
utils.WORKFLOW_RESOURCE.String(): func() utils.DBObject { return &w.WorkflowResource{} },
|
||||
utils.DATA_RESOURCE.String(): func() utils.DBObject { return &d.DataResource{} },
|
||||
utils.DATACENTER_RESOURCE.String(): func() utils.DBObject { return &dc.DatacenterResource{} },
|
||||
utils.STORAGE_RESOURCE.String(): func() utils.DBObject { return &s.StorageResource{} },
|
||||
utils.PROCESSING_RESOURCE.String(): func() utils.DBObject { return &p.ProcessingResource{} },
|
||||
utils.WORKFLOW.String(): func() utils.DBObject { return &w2.Workflow{} },
|
||||
utils.WORKFLOW_EXECUTION.String(): func() utils.DBObject { return &workflow_execution.WorkflowExecution{} },
|
||||
utils.WORKSPACE.String(): func() utils.DBObject { return &w3.Workspace{} },
|
||||
utils.RESOURCE_MODEL.String(): func() utils.DBObject { return &resource_model.ResourceModel{} },
|
||||
utils.PEER.String(): func() utils.DBObject { return &peer.Peer{} },
|
||||
utils.SHARED_WORKSPACE.String(): func() utils.DBObject { return &shared_workspace.SharedWorkspace{} },
|
||||
utils.RULE.String(): func() utils.DBObject { return &rule.Rule{} },
|
||||
utils.BOOKING.String(): func() utils.DBObject { return &booking.Booking{} },
|
||||
}
|
||||
|
||||
// Model returns the model object based on the model type
|
||||
func Model(model int) utils.DBObject {
|
||||
log := logs.GetLogger()
|
||||
if _, ok := models[tools.FromInt(model)]; ok {
|
||||
return models[tools.FromInt(model)]()
|
||||
if _, ok := models[utils.FromInt(model)]; ok {
|
||||
return models[utils.FromInt(model)]()
|
||||
}
|
||||
log.Error().Msg("Can't find model " + tools.FromInt(model) + ".")
|
||||
log.Error().Msg("Can't find model " + utils.FromInt(model) + ".")
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -5,37 +5,18 @@ import (
|
||||
"fmt"
|
||||
|
||||
"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"
|
||||
"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
|
||||
type Peer struct {
|
||||
utils.AbstractObject
|
||||
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
|
||||
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
|
||||
Services map[string]int `json:"services,omitempty" bson:"services,omitempty"` // Services is the services of the peer
|
||||
FailedExecution []PeerExecution `json:"failed_execution" bson:"failed_execution"` // FailedExecution is the list of failed executions, to be retried
|
||||
}
|
||||
|
||||
// AddExecution adds an execution to the list of failed executions
|
||||
@ -64,17 +45,13 @@ func (ao *Peer) RemoveExecution(exec PeerExecution) {
|
||||
}
|
||||
|
||||
// IsMySelf checks if the peer is the local peer
|
||||
func (ao *Peer) IsMySelf() (bool, string) {
|
||||
d, code, err := ao.GetAccessor(nil).Search(nil, SELF.String())
|
||||
if code != 200 || err != nil || len(d) == 0 {
|
||||
return false, ""
|
||||
}
|
||||
id := d[0].GetID()
|
||||
return ao.UUID == id, id
|
||||
func (ao *Peer) IsMySelf() bool {
|
||||
id, _ := static.GetMyLocalJsonPeer()
|
||||
return ao.UUID == id
|
||||
}
|
||||
|
||||
// LaunchPeerExecution launches an execution on a peer
|
||||
func (p *Peer) LaunchPeerExecution(peerID string, dataID string, dt tools.DataType, method tools.METHOD, body map[string]interface{}, caller *tools.HTTPCaller) (*PeerExecution, error) {
|
||||
func (p *Peer) LaunchPeerExecution(peerID string, dataID string, dt utils.DataType, method tools.METHOD, body map[string]interface{}, caller *tools.HTTPCaller) (*PeerExecution, error) {
|
||||
p.UUID = peerID
|
||||
return cache.LaunchPeerExecution(peerID, dataID, dt, method, body, caller) // Launch the execution on the peer through the cache
|
||||
}
|
||||
@ -84,9 +61,7 @@ func (ao *Peer) GetID() string {
|
||||
}
|
||||
|
||||
func (r *Peer) GenerateID() {
|
||||
if r.UUID == "" {
|
||||
r.UUID = uuid.New().String()
|
||||
}
|
||||
r.UUID = uuid.New().String()
|
||||
}
|
||||
|
||||
func (d *Peer) GetName() string {
|
||||
@ -95,7 +70,7 @@ func (d *Peer) GetName() string {
|
||||
|
||||
func (d *Peer) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
|
||||
data := New() // Create a new instance of the accessor
|
||||
data.Init(tools.PEER, caller) // Initialize the accessor with the PEER model type
|
||||
data.Init(utils.PEER, caller) // Initialize the accessor with the PEER model type
|
||||
return data
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,7 @@ import (
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"cloud.o-forge.io/core/oc-lib/models/utils"
|
||||
"cloud.o-forge.io/core/oc-lib/tools"
|
||||
)
|
||||
|
||||
@ -29,26 +30,18 @@ type PeerCache struct {
|
||||
}
|
||||
|
||||
// urlFormat formats the URL of the peer with the data type API function
|
||||
func (p *PeerCache) urlFormat(url string, dt tools.DataType) string {
|
||||
func (p *PeerCache) urlFormat(url string, dt utils.DataType) string {
|
||||
// localhost is replaced by the local peer URL
|
||||
// because localhost must collide on a web request security protocol
|
||||
localhost := ""
|
||||
if strings.Contains(url, "localhost") {
|
||||
localhost = "localhost"
|
||||
}
|
||||
if strings.Contains(url, "127.0.0.1") {
|
||||
localhost = "127.0.0.1"
|
||||
}
|
||||
if localhost != "" {
|
||||
r := regexp.MustCompile("(" + localhost + ":[0-9]+)")
|
||||
if strings.Contains(url, "localhost") || strings.Contains(url, "127.0.0.1") {
|
||||
url = strings.ReplaceAll(url, "localhost", dt.API())
|
||||
url = strings.ReplaceAll(url, "127.0.0.1", dt.API())
|
||||
r := regexp.MustCompile("(:[0-9]+)")
|
||||
t := r.FindString(url)
|
||||
if t != "" {
|
||||
url = strings.Replace(url, t, dt.API()+":8080/oc", -1)
|
||||
} else {
|
||||
url = strings.ReplaceAll(url, localhost, dt.API()+":8080/oc")
|
||||
url = strings.Replace(url, t, ":8080", -1)
|
||||
}
|
||||
} else {
|
||||
url = url + "/" + dt.API()
|
||||
r.ReplaceAllString(url, ":8080")
|
||||
}
|
||||
return url
|
||||
}
|
||||
@ -61,7 +54,7 @@ func (p *PeerCache) checkPeerStatus(peerID string, appName string, caller *tools
|
||||
if code != 200 { // no peer no party
|
||||
return nil, false
|
||||
}
|
||||
methods := caller.URLS[tools.PEER] // Get the methods url of the peer
|
||||
methods := caller.URLS[utils.PEER.String()] // Get the methods url of the peer
|
||||
if methods == nil {
|
||||
return res.(*Peer), false
|
||||
}
|
||||
@ -69,10 +62,8 @@ func (p *PeerCache) checkPeerStatus(peerID string, appName string, caller *tools
|
||||
if meth == "" {
|
||||
return res.(*Peer), false
|
||||
}
|
||||
url := p.urlFormat(res.(*Peer).Url, tools.PEER) + meth // Format the URL
|
||||
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
|
||||
url := p.urlFormat(res.(*Peer).Url+meth, utils.PEER) // Format the URL
|
||||
state, services := api.CheckRemotePeer(url) // Check the status of the peer
|
||||
res.(*Peer).Services = services // Update the services states of the peer
|
||||
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
|
||||
@ -80,16 +71,18 @@ func (p *PeerCache) checkPeerStatus(peerID string, appName string, caller *tools
|
||||
|
||||
// LaunchPeerExecution launches an execution on a peer
|
||||
func (p *PeerCache) LaunchPeerExecution(peerID string, dataID string,
|
||||
dt tools.DataType, method tools.METHOD, body map[string]interface{}, caller *tools.HTTPCaller) (*PeerExecution, error) {
|
||||
fmt.Println("Launching peer execution on", caller.URLS, dt, method)
|
||||
methods := caller.URLS[dt] // Get the methods url of the data type
|
||||
if m, ok := methods[method]; !ok || m == "" {
|
||||
dt utils.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
|
||||
if _, ok := methods[method]; !ok {
|
||||
return nil, errors.New("no path found")
|
||||
}
|
||||
meth := methods[method] // Get the method url to execute
|
||||
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 := 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)
|
||||
}
|
||||
url := ""
|
||||
|
||||
// Check the status of the peer
|
||||
if mypeer, ok := p.checkPeerStatus(peerID, dt.API(), caller); !ok {
|
||||
// If the peer is not reachable, add the execution to the failed executions list
|
||||
@ -113,7 +106,6 @@ func (p *PeerCache) LaunchPeerExecution(peerID string, dataID string,
|
||||
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
|
||||
}
|
||||
|
||||
@ -135,8 +127,9 @@ func (p *PeerCache) exec(url string, method tools.METHOD, body map[string]interf
|
||||
if err != nil {
|
||||
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 nil
|
||||
return err
|
||||
}
|
||||
|
@ -1,8 +1,6 @@
|
||||
package peer
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"cloud.o-forge.io/core/oc-lib/dbs"
|
||||
"cloud.o-forge.io/core/oc-lib/dbs/mongo"
|
||||
"cloud.o-forge.io/core/oc-lib/models/utils"
|
||||
@ -69,20 +67,10 @@ func (wfa peerMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int, error) {
|
||||
func (wfa *peerMongoAccessor) Search(filters *dbs.Filters, search string) ([]utils.ShallowDBObject, int, error) {
|
||||
objs := []utils.ShallowDBObject{}
|
||||
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{
|
||||
Or: map[string][]dbs.Filter{ // search by name if no filters are provided
|
||||
"abstractobject.name": {{Operator: dbs.LIKE.String(), Value: search}},
|
||||
"url": {{Operator: dbs.LIKE.String(), Value: search}},
|
||||
},
|
||||
}
|
||||
filters = &dbs.Filters{
|
||||
Or: map[string][]dbs.Filter{ // search by name if no filters are provided
|
||||
"abstractobject.name": {{Operator: dbs.LIKE.String(), Value: search}},
|
||||
},
|
||||
}
|
||||
}
|
||||
res_mongo, code, err := mongo.MONGOService.Search(filters, wfa.GetType())
|
||||
|
@ -8,11 +8,6 @@ import (
|
||||
"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
|
||||
* it defines the resource data
|
||||
@ -32,16 +27,29 @@ type AbstractResource struct {
|
||||
}
|
||||
|
||||
/*
|
||||
* GetModelType returns the type of the model key
|
||||
* GetModelValue returns the value of the model key
|
||||
*/
|
||||
func (abs *AbstractResource) GetModelType(cat string, key string) interface{} {
|
||||
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[cat][key].Type
|
||||
return abs.ResourceModel.Model[key].Value
|
||||
}
|
||||
|
||||
/*
|
||||
* GetModelType returns the type of the model key
|
||||
*/
|
||||
func (abs *AbstractResource) GetModelType(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].Type
|
||||
}
|
||||
|
||||
/*
|
||||
@ -58,19 +66,20 @@ func (abs *AbstractResource) GetModelKeys() []string {
|
||||
/*
|
||||
* GetModelReadOnly returns the readonly of the model key
|
||||
*/
|
||||
func (abs *AbstractResource) GetModelReadOnly(cat string, key string) interface{} {
|
||||
func (abs *AbstractResource) GetModelReadOnly(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[cat][key].ReadOnly
|
||||
return abs.ResourceModel.Model[key].ReadOnly
|
||||
}
|
||||
|
||||
type Model struct {
|
||||
Type string `json:"type,omitempty" bson:"type,omitempty"` // Type is the type of the model
|
||||
ReadOnly bool `json:"readonly,omitempty" bson:"readonly,omitempty"` // ReadOnly is the readonly 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
|
||||
}
|
||||
|
||||
/*
|
||||
@ -79,18 +88,15 @@ type Model struct {
|
||||
* Warning: This struct is not user available, it is only used by the system
|
||||
*/
|
||||
type ResourceModel struct {
|
||||
UUID string `json:"id,omitempty" bson:"id,omitempty" validate:"required"`
|
||||
ResourceType string `json:"resource_type,omitempty" bson:"resource_type,omitempty" validate:"required"`
|
||||
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"`
|
||||
UUID string `json:"id,omitempty" bson:"id,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"`
|
||||
}
|
||||
|
||||
func (ao *ResourceModel) GetID() string {
|
||||
return ao.UUID
|
||||
}
|
||||
|
||||
func (ao *ResourceModel) UpToDate() {}
|
||||
|
||||
func (r *ResourceModel) GenerateID() {
|
||||
r.UUID = uuid.New().String()
|
||||
}
|
||||
@ -101,7 +107,7 @@ func (d *ResourceModel) GetName() string {
|
||||
|
||||
func (d *ResourceModel) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
|
||||
data := &ResourceModelMongoAccessor{}
|
||||
data.Init(tools.RESOURCE_MODEL, caller)
|
||||
data.Init(utils.RESOURCE_MODEL, caller)
|
||||
return data
|
||||
}
|
||||
|
||||
|
@ -8,35 +8,15 @@ import (
|
||||
"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
|
||||
* it defines the resource data
|
||||
*/
|
||||
type DataResource struct {
|
||||
resource_model.AbstractResource // AbstractResource contains the basic fields of an object (id, name)
|
||||
resource_model.WebResource
|
||||
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
|
||||
resource_model.AbstractResource // AbstractResource contains the basic fields of an object (id, name)
|
||||
Protocols []string `json:"protocol,omitempty" bson:"protocol,omitempty"` //TODO Enum type
|
||||
DataType string `json:"datatype,omitempty" bson:"datatype,omitempty"` // DataType is the type of the data
|
||||
Example string `json:"example,omitempty" bson:"example,omitempty" description:"base64 encoded data"` // Example is an example of the data
|
||||
}
|
||||
|
||||
func (dma *DataResource) Deserialize(j map[string]interface{}) utils.DBObject {
|
||||
@ -60,6 +40,6 @@ func (dma *DataResource) Serialize() map[string]interface{} {
|
||||
|
||||
func (d *DataResource) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
|
||||
data := New() // Create a new instance of the accessor
|
||||
data.Init(tools.DATA_RESOURCE, caller) // Initialize the accessor with the DATA_RESOURCE model type
|
||||
data.Init(utils.DATA_RESOURCE, caller) // Initialize the accessor with the DATA_RESOURCE model type
|
||||
return data
|
||||
}
|
||||
|
@ -71,7 +71,7 @@ func (wfa dataMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int, error) {
|
||||
if err == nil && len(resources) > 0 {
|
||||
r.ResourceModel = resources[0].(*resource_model.ResourceModel)
|
||||
}
|
||||
objs = append(objs, &r) // only get the abstract resource !
|
||||
objs = append(objs, &r.AbstractResource) // only get the abstract resource !
|
||||
}
|
||||
return objs, 200, nil
|
||||
}
|
||||
@ -104,7 +104,7 @@ func (wfa *dataMongoAccessor) Search(filters *dbs.Filters, search string) ([]uti
|
||||
if err == nil && len(resources) > 0 {
|
||||
r.ResourceModel = resources[0].(*resource_model.ResourceModel)
|
||||
}
|
||||
objs = append(objs, &r) // only get the abstract resource !
|
||||
objs = append(objs, &r.AbstractResource) // only get the abstract resource !
|
||||
}
|
||||
return objs, 200, nil
|
||||
}
|
||||
|
@ -10,11 +10,7 @@ import (
|
||||
)
|
||||
|
||||
func TestStoreOneData(t *testing.T) {
|
||||
d := DataResource{
|
||||
WebResource: resource_model.WebResource{
|
||||
Protocol: "http", Path: "azerty.fr",
|
||||
},
|
||||
Example: "123456",
|
||||
d := DataResource{DataType: "jpeg", Example: "123456",
|
||||
AbstractResource: resource_model.AbstractResource{
|
||||
AbstractObject: utils.AbstractObject{Name: "testData"},
|
||||
Description: "Lorem Ipsum",
|
||||
@ -32,11 +28,7 @@ func TestStoreOneData(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestLoadOneDate(t *testing.T) {
|
||||
d := DataResource{
|
||||
WebResource: resource_model.WebResource{
|
||||
Protocol: "http", Path: "azerty.fr",
|
||||
},
|
||||
Example: "123456",
|
||||
d := DataResource{DataType: "jpeg", Example: "123456",
|
||||
AbstractResource: resource_model.AbstractResource{
|
||||
AbstractObject: utils.AbstractObject{Name: "testData"},
|
||||
Description: "Lorem Ipsum",
|
||||
|
@ -1,4 +1,4 @@
|
||||
package compute
|
||||
package datacenter
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
@ -8,53 +8,18 @@ import (
|
||||
"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]
|
||||
}
|
||||
|
||||
/*
|
||||
* ComputeResource is a struct that represents a compute resource
|
||||
* it defines the resource compute
|
||||
* DatacenterResource is a struct that represents a datacenter resource
|
||||
* it defines the resource datacenter
|
||||
*/
|
||||
type ComputeResource struct {
|
||||
type DatacenterResource struct {
|
||||
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
|
||||
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
|
||||
}
|
||||
|
||||
func (dma *ComputeResource) Deserialize(j map[string]interface{}) utils.DBObject {
|
||||
func (dma *DatacenterResource) Deserialize(j map[string]interface{}) utils.DBObject {
|
||||
b, err := json.Marshal(j)
|
||||
if err != nil {
|
||||
return nil
|
||||
@ -63,7 +28,7 @@ func (dma *ComputeResource) Deserialize(j map[string]interface{}) utils.DBObject
|
||||
return dma
|
||||
}
|
||||
|
||||
func (dma *ComputeResource) Serialize() map[string]interface{} {
|
||||
func (dma *DatacenterResource) Serialize() map[string]interface{} {
|
||||
var m map[string]interface{}
|
||||
b, err := json.Marshal(dma)
|
||||
if err != nil {
|
||||
@ -73,9 +38,9 @@ func (dma *ComputeResource) Serialize() map[string]interface{} {
|
||||
return m
|
||||
}
|
||||
|
||||
func (d *ComputeResource) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
|
||||
func (d *DatacenterResource) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
|
||||
data := New()
|
||||
data.Init(tools.COMPUTE_RESOURCE, caller)
|
||||
data.Init(utils.DATACENTER_RESOURCE, caller)
|
||||
return data
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
package compute
|
||||
package datacenter
|
||||
|
||||
import (
|
||||
"cloud.o-forge.io/core/oc-lib/dbs"
|
||||
@ -7,39 +7,39 @@ import (
|
||||
"cloud.o-forge.io/core/oc-lib/models/utils"
|
||||
)
|
||||
|
||||
type computeMongoAccessor struct {
|
||||
type datacenterMongoAccessor struct {
|
||||
utils.AbstractAccessor // AbstractAccessor contains the basic fields of an accessor (model, caller)
|
||||
}
|
||||
|
||||
// New creates a new instance of the computeMongoAccessor
|
||||
func New() *computeMongoAccessor {
|
||||
return &computeMongoAccessor{}
|
||||
// New creates a new instance of the datacenterMongoAccessor
|
||||
func New() *datacenterMongoAccessor {
|
||||
return &datacenterMongoAccessor{}
|
||||
}
|
||||
|
||||
/*
|
||||
* Nothing special here, just the basic CRUD operations
|
||||
*/
|
||||
|
||||
func (dca *computeMongoAccessor) DeleteOne(id string) (utils.DBObject, int, error) {
|
||||
func (dca *datacenterMongoAccessor) DeleteOne(id string) (utils.DBObject, int, error) {
|
||||
return dca.GenericDeleteOne(id, dca)
|
||||
}
|
||||
|
||||
func (dca *computeMongoAccessor) UpdateOne(set utils.DBObject, id string) (utils.DBObject, int, error) {
|
||||
set.(*ComputeResource).ResourceModel = nil
|
||||
return dca.GenericUpdateOne(set, id, dca, &ComputeResource{})
|
||||
func (dca *datacenterMongoAccessor) UpdateOne(set utils.DBObject, id string) (utils.DBObject, int, error) {
|
||||
set.(*DatacenterResource).ResourceModel = nil
|
||||
return dca.GenericUpdateOne(set, id, dca, &DatacenterResource{})
|
||||
}
|
||||
|
||||
func (dca *computeMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject, int, error) {
|
||||
data.(*ComputeResource).ResourceModel = nil
|
||||
func (dca *datacenterMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject, int, error) {
|
||||
data.(*DatacenterResource).ResourceModel = nil
|
||||
return dca.GenericStoreOne(data, dca)
|
||||
}
|
||||
|
||||
func (dca *computeMongoAccessor) CopyOne(data utils.DBObject) (utils.DBObject, int, error) {
|
||||
func (dca *datacenterMongoAccessor) CopyOne(data utils.DBObject) (utils.DBObject, int, error) {
|
||||
return dca.GenericStoreOne(data, dca)
|
||||
}
|
||||
|
||||
func (dca *computeMongoAccessor) LoadOne(id string) (utils.DBObject, int, error) {
|
||||
var compute ComputeResource
|
||||
func (dca *datacenterMongoAccessor) LoadOne(id string) (utils.DBObject, int, error) {
|
||||
var datacenter DatacenterResource
|
||||
|
||||
res_mongo, code, err := mongo.MONGOService.LoadOne(id, dca.GetType())
|
||||
if err != nil {
|
||||
@ -47,23 +47,23 @@ func (dca *computeMongoAccessor) LoadOne(id string) (utils.DBObject, int, error)
|
||||
return nil, code, err
|
||||
}
|
||||
|
||||
res_mongo.Decode(&compute)
|
||||
res_mongo.Decode(&datacenter)
|
||||
accessor := (&resource_model.ResourceModel{}).GetAccessor(nil)
|
||||
resources, _, err := accessor.Search(nil, dca.GetType())
|
||||
if err == nil && len(resources) > 0 {
|
||||
compute.ResourceModel = resources[0].(*resource_model.ResourceModel)
|
||||
datacenter.ResourceModel = resources[0].(*resource_model.ResourceModel)
|
||||
}
|
||||
return &compute, 200, nil
|
||||
return &datacenter, 200, nil
|
||||
}
|
||||
|
||||
func (wfa computeMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int, error) {
|
||||
func (wfa datacenterMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int, error) {
|
||||
objs := []utils.ShallowDBObject{}
|
||||
res_mongo, code, err := mongo.MONGOService.LoadAll(wfa.GetType())
|
||||
if err != nil {
|
||||
wfa.Logger.Error().Msg("Could not retrieve any from db. Error: " + err.Error())
|
||||
return nil, code, err
|
||||
}
|
||||
var results []ComputeResource
|
||||
var results []DatacenterResource
|
||||
if err = res_mongo.All(mongo.MngoCtx, &results); err != nil {
|
||||
return nil, 404, err
|
||||
}
|
||||
@ -73,12 +73,12 @@ func (wfa computeMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int, error)
|
||||
if err == nil && len(resources) > 0 {
|
||||
r.ResourceModel = resources[0].(*resource_model.ResourceModel)
|
||||
}
|
||||
objs = append(objs, &r) // only get the abstract resource !
|
||||
objs = append(objs, &r.AbstractResource) // only get the abstract resource !
|
||||
}
|
||||
return objs, 200, nil
|
||||
}
|
||||
|
||||
func (wfa *computeMongoAccessor) Search(filters *dbs.Filters, search string) ([]utils.ShallowDBObject, int, error) {
|
||||
func (wfa *datacenterMongoAccessor) Search(filters *dbs.Filters, search string) ([]utils.ShallowDBObject, int, error) {
|
||||
objs := []utils.ShallowDBObject{}
|
||||
if (filters == nil || len(filters.And) == 0 || len(filters.Or) == 0) && search != "" {
|
||||
filters = &dbs.Filters{
|
||||
@ -96,7 +96,7 @@ func (wfa *computeMongoAccessor) Search(filters *dbs.Filters, search string) ([]
|
||||
wfa.Logger.Error().Msg("Could not store to db. Error: " + err.Error())
|
||||
return nil, code, err
|
||||
}
|
||||
var results []ComputeResource
|
||||
var results []DatacenterResource
|
||||
if err = res_mongo.All(mongo.MngoCtx, &results); err != nil {
|
||||
return nil, 404, err
|
||||
}
|
||||
@ -106,7 +106,7 @@ func (wfa *computeMongoAccessor) Search(filters *dbs.Filters, search string) ([]
|
||||
if err == nil && len(resources) > 0 {
|
||||
r.ResourceModel = resources[0].(*resource_model.ResourceModel)
|
||||
}
|
||||
objs = append(objs, &r) // only get the abstract resource !
|
||||
objs = append(objs, &r.AbstractResource) // only get the abstract resource !
|
||||
}
|
||||
return objs, 200, nil
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package compute
|
||||
package datacenter
|
||||
|
||||
import (
|
||||
"testing"
|
||||
@ -9,10 +9,10 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestStoreOneCompute(t *testing.T) {
|
||||
dc := ComputeResource{
|
||||
func TestStoreOneDatacenter(t *testing.T) {
|
||||
dc := DatacenterResource{
|
||||
AbstractResource: resource_model.AbstractResource{
|
||||
AbstractObject: utils.AbstractObject{Name: "testCompute"},
|
||||
AbstractObject: utils.AbstractObject{Name: "testDatacenter"},
|
||||
Description: "Lorem Ipsum",
|
||||
Logo: "azerty.com",
|
||||
Owner: "toto",
|
||||
@ -27,10 +27,10 @@ func TestStoreOneCompute(t *testing.T) {
|
||||
assert.NotEmpty(t, id)
|
||||
}
|
||||
|
||||
func TestLoadOneCompute(t *testing.T) {
|
||||
dc := ComputeResource{
|
||||
func TestLoadOneDatacenter(t *testing.T) {
|
||||
dc := DatacenterResource{
|
||||
AbstractResource: resource_model.AbstractResource{
|
||||
AbstractObject: utils.AbstractObject{Name: "testCompute"},
|
||||
AbstractObject: utils.AbstractObject{Name: "testDatacenter"},
|
||||
Description: "Lorem Ipsum",
|
||||
Logo: "azerty.com",
|
||||
Owner: "toto",
|
@ -4,41 +4,24 @@ import (
|
||||
"encoding/json"
|
||||
|
||||
"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/datacenter"
|
||||
"cloud.o-forge.io/core/oc-lib/models/utils"
|
||||
"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
|
||||
* it defines the resource processing
|
||||
*/
|
||||
type ProcessingResource struct {
|
||||
resource_model.AbstractResource
|
||||
IsService bool `json:"is_service,omitempty" bson:"is_service,omitempty"` // IsService is a flag that indicates if the processing is a service
|
||||
CPUs []*compute.CPU `bson:"cpus,omitempty" json:"cp_us,omitempty"` // CPUs is the list of CPUs
|
||||
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
|
||||
CPUs []*datacenter.CPU `bson:"cpus,omitempty" json:"cp_us,omitempty"` // CPUs is the list of CPUs
|
||||
GPUs []*datacenter.GPU `bson:"gpus,omitempty" json:"gp_us,omitempty"` // GPUs is the list of GPUs
|
||||
RAM *datacenter.RAM `bson:"ram,omitempty" json:"ram,omitempty"` // RAM is the RAM
|
||||
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
|
||||
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
|
||||
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 {
|
||||
@ -62,6 +45,6 @@ func (dma *ProcessingResource) Serialize() map[string]interface{} {
|
||||
|
||||
func (d *ProcessingResource) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
|
||||
data := New() // Create a new instance of the accessor
|
||||
data.Init(tools.PROCESSING_RESOURCE, caller) // Initialize the accessor with the PROCESSING_RESOURCE model type
|
||||
data.Init(utils.PROCESSING_RESOURCE, caller) // Initialize the accessor with the PROCESSING_RESOURCE model type
|
||||
return data
|
||||
}
|
||||
|
@ -74,7 +74,7 @@ func (wfa processingMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int, erro
|
||||
if err == nil && len(resources) > 0 {
|
||||
r.ResourceModel = resources[0].(*resource_model.ResourceModel)
|
||||
}
|
||||
objs = append(objs, &r) // only get the abstract resource !
|
||||
objs = append(objs, &r.AbstractResource) // only get the abstract resource !
|
||||
}
|
||||
return objs, 200, nil
|
||||
}
|
||||
@ -108,7 +108,7 @@ func (wfa *processingMongoAccessor) Search(filters *dbs.Filters, search string)
|
||||
if err == nil && len(resources) > 0 {
|
||||
r.ResourceModel = resources[0].(*resource_model.ResourceModel)
|
||||
}
|
||||
objs = append(objs, &r) // only get the abstract resource !
|
||||
objs = append(objs, &r.AbstractResource) // only get the abstract resource !
|
||||
}
|
||||
return objs, 200, nil
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ package resources
|
||||
import (
|
||||
"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/compute"
|
||||
"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/storage"
|
||||
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"`
|
||||
Storages []string `bson:"storages,omitempty" json:"storages,omitempty"`
|
||||
Processings []string `bson:"processings,omitempty" json:"processings,omitempty"`
|
||||
Computes []string `bson:"computes,omitempty" json:"computes,omitempty"`
|
||||
Datacenters []string `bson:"datacenters,omitempty" json:"datacenters,omitempty"`
|
||||
Workflows []string `bson:"workflows,omitempty" json:"workflows,omitempty"`
|
||||
|
||||
DataResources []*data.DataResource `bson:"-" json:"data_resources,omitempty"`
|
||||
StorageResources []*storage.StorageResource `bson:"-" json:"storage_resources,omitempty"`
|
||||
ProcessingResources []*processing.ProcessingResource `bson:"-" json:"processing_resources,omitempty"`
|
||||
ComputeResources []*compute.ComputeResource `bson:"-" json:"compute_resources,omitempty"`
|
||||
DatacenterResources []*datacenter.DatacenterResource `bson:"-" json:"datacenter_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"`
|
||||
Processing *processing.ProcessingResource `bson:"processing,omitempty" json:"processing,omitempty"`
|
||||
Storage *storage.StorageResource `bson:"storage,omitempty" json:"storage,omitempty"`
|
||||
Compute *compute.ComputeResource `bson:"compute,omitempty" json:"compute,omitempty"`
|
||||
Datacenter *datacenter.DatacenterResource `bson:"datacenter,omitempty" json:"datacenter,omitempty"`
|
||||
Workflow *w.WorkflowResource `bson:"workflow,omitempty" json:"workflow,omitempty"`
|
||||
}
|
||||
|
||||
@ -47,11 +47,12 @@ func (i *ItemResource) GetAbstractRessource() *resource_model.AbstractResource {
|
||||
if(i.Storage != nil){
|
||||
return &i.Storage.AbstractResource
|
||||
}
|
||||
if(i.Compute != nil){
|
||||
return &i.Compute.AbstractResource
|
||||
if(i.Datacenter != nil){
|
||||
return &i.Datacenter.AbstractResource
|
||||
}
|
||||
if(i.Workflow != nil){
|
||||
return &i.Workflow.AbstractResource
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
@ -8,54 +8,25 @@ import (
|
||||
"cloud.o-forge.io/core/oc-lib/tools"
|
||||
)
|
||||
|
||||
type StorageSize int
|
||||
|
||||
// StorageType - Enum that defines the type of storage
|
||||
const (
|
||||
GB StorageSize = iota
|
||||
MB
|
||||
KB
|
||||
)
|
||||
|
||||
var argoType = [...]string{
|
||||
"Gi",
|
||||
"Mi",
|
||||
"Ki",
|
||||
type URL 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
|
||||
}
|
||||
|
||||
// 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
|
||||
* it defines the resource storage
|
||||
*/
|
||||
type StorageResource struct {
|
||||
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
|
||||
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
|
||||
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
|
||||
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
|
||||
resource_model.AbstractResource // AbstractResource contains the basic fields of an object (id, name)
|
||||
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
|
||||
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
|
||||
|
||||
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
|
||||
Throughput string `bson:"throughput,omitempty" json:"throughput,omitempty"` // Throughput is the throughput of the storage
|
||||
}
|
||||
|
||||
func (dma *StorageResource) Deserialize(j map[string]interface{}) utils.DBObject {
|
||||
@ -79,6 +50,6 @@ func (dma *StorageResource) Serialize() map[string]interface{} {
|
||||
|
||||
func (d *StorageResource) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
|
||||
data := New() // Create a new instance of the accessor
|
||||
data.Init(tools.STORAGE_RESOURCE, caller) // Initialize the accessor with the STORAGE_RESOURCE model type
|
||||
data.Init(utils.STORAGE_RESOURCE, caller) // Initialize the accessor with the STORAGE_RESOURCE model type
|
||||
return data
|
||||
}
|
||||
|
@ -74,7 +74,7 @@ func (wfa storageMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int, error)
|
||||
if err == nil && len(resources) > 0 {
|
||||
r.ResourceModel = resources[0].(*resource_model.ResourceModel)
|
||||
}
|
||||
objs = append(objs, &r) // only get the abstract resource !
|
||||
objs = append(objs, &r.AbstractResource) // only get the abstract resource !
|
||||
}
|
||||
return objs, 200, nil
|
||||
}
|
||||
@ -108,7 +108,7 @@ func (wfa *storageMongoAccessor) Search(filters *dbs.Filters, search string) ([]
|
||||
if err == nil && len(resources) > 0 {
|
||||
r.ResourceModel = resources[0].(*resource_model.ResourceModel)
|
||||
}
|
||||
objs = append(objs, &r) // only get the abstract resource !
|
||||
objs = append(objs, &r.AbstractResource) // only get the abstract resource !
|
||||
}
|
||||
return objs, 200, nil
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ import (
|
||||
)
|
||||
|
||||
func TestStoreOneStorage(t *testing.T) {
|
||||
s := StorageResource{Size: 123, WebResource: resource_model.WebResource{Protocol: "http", Path: "azerty.fr"},
|
||||
s := StorageResource{Size: 123, Url: &URL{Protocol: "http", Path: "azerty.fr"},
|
||||
AbstractResource: resource_model.AbstractResource{
|
||||
AbstractObject: utils.AbstractObject{Name: "testData"},
|
||||
Description: "Lorem Ipsum",
|
||||
@ -28,7 +28,7 @@ func TestStoreOneStorage(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestLoadOneStorage(t *testing.T) {
|
||||
s := StorageResource{Size: 123, WebResource: resource_model.WebResource{Protocol: "http", Path: "azerty.fr"},
|
||||
s := StorageResource{Size: 123, Url: &URL{Protocol: "http", Path: "azerty.fr"},
|
||||
AbstractResource: resource_model.AbstractResource{
|
||||
AbstractObject: utils.AbstractObject{Name: "testData"},
|
||||
Description: "Lorem Ipsum",
|
||||
|
@ -1,10 +1,6 @@
|
||||
package graph
|
||||
|
||||
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"
|
||||
)
|
||||
import "cloud.o-forge.io/core/oc-lib/models/resources"
|
||||
|
||||
// Graph is a struct that represents a graph
|
||||
type Graph struct {
|
||||
@ -13,23 +9,6 @@ type Graph struct {
|
||||
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
|
||||
type GraphItem struct {
|
||||
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 {
|
||||
data := New() // Create a new instance of the accessor
|
||||
data.Init(tools.WORKFLOW_RESOURCE, caller) // Initialize the accessor with the WORKFLOW_RESOURCE model type
|
||||
data.Init(utils.WORKFLOW_RESOURCE, caller) // Initialize the accessor with the WORKFLOW_RESOURCE model type
|
||||
return data
|
||||
}
|
||||
|
||||
|
@ -73,7 +73,7 @@ func (wfa workflowResourceMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int
|
||||
if err == nil && len(resources) > 0 {
|
||||
r.ResourceModel = resources[0].(*resource_model.ResourceModel)
|
||||
}
|
||||
objs = append(objs, &r)
|
||||
objs = append(objs, &r.AbstractResource)
|
||||
}
|
||||
return objs, 200, nil
|
||||
}
|
||||
@ -107,7 +107,7 @@ func (wfa *workflowResourceMongoAccessor) Search(filters *dbs.Filters, search st
|
||||
if err == nil && len(resources) > 0 {
|
||||
r.ResourceModel = resources[0].(*resource_model.ResourceModel)
|
||||
}
|
||||
objs = append(objs, &r)
|
||||
objs = append(objs, &r.AbstractResource)
|
||||
}
|
||||
return objs, 200, nil
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ package utils
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"cloud.o-forge.io/core/oc-lib/dbs"
|
||||
"cloud.o-forge.io/core/oc-lib/dbs/mongo"
|
||||
@ -23,10 +22,8 @@ var validate = validator.New(validator.WithRequiredStructEnabled())
|
||||
* every data in base root model should inherit from this struct (only exception is the ResourceModel)
|
||||
*/
|
||||
type AbstractObject struct {
|
||||
UUID string `json:"id,omitempty" bson:"id,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"`
|
||||
UUID string `json:"id,omitempty" bson:"id,omitempty" validate:"required"`
|
||||
Name string `json:"name,omitempty" bson:"name,omitempty" validate:"required"`
|
||||
}
|
||||
|
||||
// GetID returns the id of the object (abstract)
|
||||
@ -39,11 +36,6 @@ func (ao *AbstractObject) GetName() string {
|
||||
return ao.Name
|
||||
}
|
||||
|
||||
func (ao *AbstractObject) UpToDate() {
|
||||
ao.UpdateDate = time.Now()
|
||||
// ao.LastPeerWriter, _ = static.GetMyLocalJsonPeer()
|
||||
}
|
||||
|
||||
// GetAccessor returns the accessor of the object (abstract)
|
||||
func (dma *AbstractObject) GetAccessor(caller *tools.HTTPCaller) Accessor {
|
||||
return nil
|
||||
@ -89,7 +81,7 @@ func (dma *AbstractAccessor) GetCaller() *tools.HTTPCaller {
|
||||
}
|
||||
|
||||
// Init initializes the accessor with the data type and the http caller
|
||||
func (dma *AbstractAccessor) Init(t tools.DataType, caller *tools.HTTPCaller) {
|
||||
func (dma *AbstractAccessor) Init(t DataType, caller *tools.HTTPCaller) {
|
||||
dma.Logger = logs.CreateLogger(t.String()) // Create a logger with the data type
|
||||
dma.Caller = caller // Set the caller
|
||||
dma.Type = t.String() // Set the data type
|
||||
@ -160,14 +152,3 @@ func (dma *AbstractAccessor) GenericUpdateOne(set DBObject, id string, accessor
|
||||
}
|
||||
return accessor.LoadOne(id)
|
||||
}
|
||||
|
||||
// GenericLoadOne loads one object from the database (generic)
|
||||
// json expected in entry is a flatted object no need to respect the inheritance hierarchy
|
||||
func (dma *AbstractAccessor) GenericRawUpdateOne(set DBObject, id string, accessor Accessor) (DBObject, int, error) {
|
||||
id, code, err := mongo.MONGOService.UpdateOne(set, id, accessor.GetType())
|
||||
if err != nil {
|
||||
dma.Logger.Error().Msg("Could not update " + id + " to db. Error: " + err.Error())
|
||||
return nil, code, err
|
||||
}
|
||||
return accessor.LoadOne(id)
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
package tools
|
||||
package utils
|
||||
|
||||
type DataType int
|
||||
|
||||
@ -8,46 +8,34 @@ const (
|
||||
DATA_RESOURCE
|
||||
PROCESSING_RESOURCE
|
||||
STORAGE_RESOURCE
|
||||
COMPUTE_RESOURCE
|
||||
DATACENTER_RESOURCE
|
||||
WORKFLOW_RESOURCE
|
||||
WORKFLOW
|
||||
WORKFLOW_EXECUTION
|
||||
WORKSPACE
|
||||
RESOURCE_MODEL
|
||||
PEER
|
||||
COLLABORATIVE_AREA
|
||||
SHARED_WORKSPACE
|
||||
RULE
|
||||
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
|
||||
var DefaultAPI = [...]string{
|
||||
NOAPI,
|
||||
CATALOGAPI,
|
||||
CATALOGAPI,
|
||||
CATALOGAPI,
|
||||
CATALOGAPI,
|
||||
CATALOGAPI,
|
||||
WORKFLOWAPI,
|
||||
NOAPI,
|
||||
WORKSPACEAPI,
|
||||
CATALOGAPI,
|
||||
PEERSAPI,
|
||||
SHAREDAPI,
|
||||
SHAREDAPI,
|
||||
DATACENTERAPI,
|
||||
NOAPI,
|
||||
NOAPI,
|
||||
"",
|
||||
"oc-catalog",
|
||||
"oc-catalog",
|
||||
"oc-catalog",
|
||||
"oc-catalog",
|
||||
"oc-catalog",
|
||||
"oc-workflow",
|
||||
"",
|
||||
"oc-workspace",
|
||||
"",
|
||||
"oc-peers",
|
||||
"oc-shared",
|
||||
"oc-shared",
|
||||
"oc-datacenter",
|
||||
}
|
||||
|
||||
// Bind the standard data name to the data type
|
||||
@ -56,7 +44,7 @@ var Str = [...]string{
|
||||
"data_resource",
|
||||
"processing_resource",
|
||||
"storage_resource",
|
||||
"compute_resource",
|
||||
"datacenter_resource",
|
||||
"workflow_resource",
|
||||
"workflow",
|
||||
"workflow_execution",
|
||||
@ -66,8 +54,6 @@ var Str = [...]string{
|
||||
"shared_workspace",
|
||||
"rule",
|
||||
"booking",
|
||||
"workflow_history",
|
||||
"workspace_history",
|
||||
}
|
||||
|
||||
func FromInt(i int) string {
|
@ -19,7 +19,6 @@ type DBObject interface {
|
||||
GenerateID()
|
||||
GetID() string
|
||||
GetName() string
|
||||
UpToDate()
|
||||
Deserialize(j map[string]interface{}) DBObject
|
||||
Serialize() map[string]interface{}
|
||||
GetAccessor(caller *tools.HTTPCaller) Accessor
|
||||
@ -27,7 +26,7 @@ type DBObject interface {
|
||||
|
||||
// Accessor is an interface that defines the basic methods for an Accessor
|
||||
type Accessor interface {
|
||||
Init(t tools.DataType, caller *tools.HTTPCaller)
|
||||
Init(t DataType, caller *tools.HTTPCaller)
|
||||
GetType() string
|
||||
GetCaller() *tools.HTTPCaller
|
||||
Search(filters *dbs.Filters, search string) ([]ShallowDBObject, int, error)
|
||||
|
@ -6,8 +6,7 @@ import (
|
||||
|
||||
"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/compute"
|
||||
"cloud.o-forge.io/core/oc-lib/models/resources/storage"
|
||||
"cloud.o-forge.io/core/oc-lib/models/resources/datacenter"
|
||||
"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/tools"
|
||||
@ -27,50 +26,16 @@ type AbstractWorkflow struct {
|
||||
Shared []string `json:"shared,omitempty" bson:"shared,omitempty"` // Shared is the ID of the shared workflow
|
||||
}
|
||||
|
||||
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
|
||||
// tool function to check if a link is a link between a datacenter and a resource
|
||||
func (w *AbstractWorkflow) isDCLink(link graph.GraphLink) (bool, string) {
|
||||
if w.Graph == nil || w.Graph.Items == nil {
|
||||
return false, ""
|
||||
}
|
||||
if d, ok := w.Graph.Items[link.Source.ID]; ok && d.Compute != nil {
|
||||
return true, d.Compute.UUID
|
||||
if d, ok := w.Graph.Items[link.Source.ID]; ok && d.Datacenter != nil {
|
||||
return true, d.Datacenter.UUID
|
||||
}
|
||||
if d, ok := w.Graph.Items[link.Destination.ID]; ok && d.Compute != nil {
|
||||
return true, d.Compute.UUID
|
||||
if d, ok := w.Graph.Items[link.Destination.ID]; ok && d.Datacenter != nil {
|
||||
return true, d.Datacenter.UUID
|
||||
}
|
||||
return false, ""
|
||||
}
|
||||
@ -92,19 +57,19 @@ func (wfa *Workflow) CheckBooking(caller *tools.HTTPCaller) (bool, error) {
|
||||
if wfa.Graph == nil { // no graph no booking
|
||||
return false, nil
|
||||
}
|
||||
accessor := (&compute.ComputeResource{}).GetAccessor(nil)
|
||||
accessor := (&datacenter.DatacenterResource{}).GetAccessor(nil)
|
||||
for _, link := range wfa.Graph.Links {
|
||||
if ok, dc_id := wfa.isDCLink(link); ok { // check if the link is a link between a compute and a resource
|
||||
if ok, dc_id := wfa.isDCLink(link); ok { // check if the link is a link between a datacenter and a resource
|
||||
dc, code, _ := accessor.LoadOne(dc_id)
|
||||
if code != 200 {
|
||||
continue
|
||||
}
|
||||
// CHECK BOOKING ON PEER, compute could be a remote one
|
||||
peerID := dc.(*compute.ComputeResource).PeerID
|
||||
// CHECK BOOKING ON PEER, datacenter could be a remote one
|
||||
peerID := dc.(*datacenter.DatacenterResource).PeerID
|
||||
if peerID == "" {
|
||||
return false, errors.New("no peer id")
|
||||
} // no peer id no booking, we need to know where to book
|
||||
_, err := (&peer.Peer{}).LaunchPeerExecution(peerID, dc_id, tools.BOOKING, tools.GET, nil, caller)
|
||||
_, err := (&peer.Peer{}).LaunchPeerExecution(peerID, dc_id, utils.BOOKING, tools.GET, nil, caller)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
@ -119,7 +84,7 @@ func (d *Workflow) GetName() string {
|
||||
|
||||
func (d *Workflow) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
|
||||
data := New() // Create a new instance of the accessor
|
||||
data.Init(tools.WORKFLOW, caller) // Initialize the accessor with the WORKFLOW model type
|
||||
data.Init(utils.WORKFLOW, caller) // Initialize the accessor with the WORKFLOW model type
|
||||
return data
|
||||
}
|
||||
|
||||
|
@ -1,34 +0,0 @@
|
||||
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,18 +2,17 @@ package workflow
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"cloud.o-forge.io/core/oc-lib/dbs"
|
||||
"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/resources"
|
||||
"cloud.o-forge.io/core/oc-lib/models/resources/compute"
|
||||
"cloud.o-forge.io/core/oc-lib/models/resources/datacenter"
|
||||
"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/workspace"
|
||||
"cloud.o-forge.io/core/oc-lib/models/workspace/shared/shallow_shared_workspace"
|
||||
"cloud.o-forge.io/core/oc-lib/tools"
|
||||
cron "github.com/robfig/cron/v3"
|
||||
)
|
||||
@ -96,9 +95,9 @@ func (wfa *workflowMongoAccessor) DeleteOne(id string) (utils.DBObject, int, err
|
||||
}, true) // delete the executions
|
||||
res, code, err := wfa.GenericDeleteOne(id, wfa)
|
||||
if res != nil && code == 200 {
|
||||
wfa.execute(res.(*Workflow), true, false) // up to date the workspace for the workflow
|
||||
wfa.share(res.(*Workflow), true, wfa.Caller)
|
||||
wfa.execute(res.(*Workflow), false) // up to date the workspace for the workflow
|
||||
}
|
||||
wfa.share(res.(*Workflow), true, wfa.Caller) // send the deletion to the peers where workflow is shared
|
||||
return res, code, err
|
||||
}
|
||||
|
||||
@ -108,10 +107,10 @@ func (wfa *workflowMongoAccessor) DeleteOne(id string) (utils.DBObject, int, err
|
||||
* it returns an error if the booking fails
|
||||
*/
|
||||
func (wfa *workflowMongoAccessor) book(id string, realData *Workflow, execs []*workflow_execution.WorkflowExecution) error {
|
||||
if wfa.Caller == nil || wfa.Caller.URLS == nil || wfa.Caller.URLS[tools.BOOKING] == nil {
|
||||
if wfa.Caller == nil || wfa.Caller.URLS == nil || wfa.Caller.URLS[utils.BOOKING.String()] == nil {
|
||||
return errors.New("no caller defined")
|
||||
}
|
||||
methods := wfa.Caller.URLS[tools.BOOKING]
|
||||
methods := wfa.Caller.URLS[utils.BOOKING.String()]
|
||||
if _, ok := methods[tools.POST]; !ok {
|
||||
return errors.New("no path found")
|
||||
}
|
||||
@ -125,27 +124,26 @@ func (wfa *workflowMongoAccessor) book(id string, realData *Workflow, execs []*w
|
||||
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)
|
||||
accessor := (&compute.ComputeResource{}).GetAccessor(nil)
|
||||
accessor := (&datacenter.DatacenterResource{}).GetAccessor(nil)
|
||||
for _, link := range g.Links {
|
||||
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
|
||||
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
|
||||
dc, code, _ := accessor.LoadOne(dc_id)
|
||||
if code != 200 {
|
||||
continue
|
||||
}
|
||||
// CHECK BOOKING
|
||||
peerID := dc.(*compute.ComputeResource).PeerID
|
||||
peerID := dc.(*datacenter.DatacenterResource).PeerID
|
||||
if peerID == "" { // no peer id no booking
|
||||
continue
|
||||
}
|
||||
// BOOKING ON PEER
|
||||
_, err := (&peer.Peer{}).LaunchPeerExecution(peerID, "", tools.BOOKING, tools.POST,
|
||||
_, err := (&peer.Peer{}).LaunchPeerExecution(peerID, "", utils.BOOKING, tools.POST,
|
||||
(&workflow_execution.WorkflowExecutions{ // it's the standard model for booking see OC-PEER
|
||||
WorkflowID: id, // set the workflow id "WHO"
|
||||
ResourceID: dc_id, // set the compute id "WHERE"
|
||||
ResourceID: dc_id, // set the datacenter id "WHERE"
|
||||
Executions: execs, // set the executions to book "WHAT"
|
||||
}).Serialize(), wfa.Caller)
|
||||
if err != nil {
|
||||
fmt.Println("BOOKING", err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
@ -158,28 +156,26 @@ 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
|
||||
*/
|
||||
func (wfa *workflowMongoAccessor) share(realData *Workflow, delete bool, caller *tools.HTTPCaller) {
|
||||
if realData.Shared == nil || len(realData.Shared) == 0 || caller.Disabled { // no shared no sharing
|
||||
if realData.Shared == nil || len(realData.Shared) == 0 { // no shared no sharing
|
||||
return
|
||||
}
|
||||
for _, sharedID := range realData.Shared { // loop through the shared ids
|
||||
access := (&shallow_collaborative_area.ShallowCollaborativeArea{}).GetAccessor(nil)
|
||||
access := (&shallow_shared_workspace.ShallowSharedWorkspace{}).GetAccessor(nil)
|
||||
res, code, _ := access.LoadOne(sharedID)
|
||||
if code != 200 {
|
||||
continue
|
||||
}
|
||||
var err error
|
||||
paccess := &peer.Peer{}
|
||||
for _, p := range res.(*shallow_collaborative_area.ShallowCollaborativeArea).Peers {
|
||||
for _, p := range res.(*shallow_shared_workspace.ShallowSharedWorkspace).Peers {
|
||||
paccess.UUID = p
|
||||
if ok, _ := paccess.IsMySelf(); ok { // if the peer is the current peer, never share because it will create a loop
|
||||
if paccess.IsMySelf() { // if the peer is the current peer, never share because it will create a loop
|
||||
continue
|
||||
}
|
||||
if delete { // if the workflow is deleted, share the deletion
|
||||
history := NewHistory()
|
||||
history.StoreOne(history.MapFromWorkflow(res.(*Workflow)))
|
||||
_, err = paccess.LaunchPeerExecution(p, res.GetID(), tools.WORKFLOW, tools.DELETE, map[string]interface{}{}, caller)
|
||||
_, err = paccess.LaunchPeerExecution(p, res.GetID(), utils.WORKFLOW, tools.DELETE, map[string]interface{}{}, caller)
|
||||
} else { // if the workflow is updated, share the update
|
||||
_, err = paccess.LaunchPeerExecution(p, res.GetID(), tools.WORKFLOW, tools.PUT, res.Serialize(), caller)
|
||||
_, err = paccess.LaunchPeerExecution(p, res.GetID(), utils.WORKFLOW, tools.PUT, res.Serialize(), caller)
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
@ -192,40 +188,46 @@ 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
|
||||
*/
|
||||
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
|
||||
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
|
||||
"workflow_id": id,
|
||||
}, tools.WORKFLOW_EXECUTION.String())
|
||||
err := wfa.book(id, realData, []*workflow_execution.WorkflowExecution{}) // delete the booking of the workflow on the peers
|
||||
fmt.Println("DELETE BOOKING", err)
|
||||
nats.SetNATSPub(tools.WORKFLOW.String(), tools.REMOVE, realData) // send the deletion to the nats
|
||||
if err != nil {
|
||||
return 409, err
|
||||
if !realData.ScheduleActive { // if the schedule is not active, delete the executions
|
||||
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
|
||||
"workflow_id": id,
|
||||
}, utils.WORKFLOW_EXECUTION.String())
|
||||
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
|
||||
return 200, err
|
||||
}
|
||||
|
||||
accessor := (&workflow_execution.WorkflowExecution{}).GetAccessor(nil)
|
||||
execs, err := wfa.getExecutions(id, realData) // get the executions of the workflow
|
||||
if err != nil {
|
||||
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
|
||||
fmt.Println("BOOKING", err)
|
||||
if err != nil {
|
||||
return 409, err // if the booking fails, return an error for integrity between peers
|
||||
}
|
||||
fmt.Println("BOOKING", delete)
|
||||
for _, obj := range execs {
|
||||
_, code, err := accessor.StoreOne(obj)
|
||||
fmt.Println("EXEC", code, err)
|
||||
if code != 200 {
|
||||
return code, err
|
||||
}
|
||||
if delete { // if delete is set to true, delete the executions
|
||||
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 {
|
||||
_, code, err := accessor.StoreOne(obj)
|
||||
if code != 200 {
|
||||
return code, err
|
||||
}
|
||||
}
|
||||
nats.SetNATSPub(utils.WORKFLOW.String(), tools.CREATE, realData) // send the creation to the nats
|
||||
} else {
|
||||
return 422, err
|
||||
}
|
||||
nats.SetNATSPub(tools.WORKFLOW.String(), tools.CREATE, realData) // send the creation to the nats
|
||||
return 200, nil
|
||||
}
|
||||
|
||||
@ -241,21 +243,20 @@ func (wfa *workflowMongoAccessor) UpdateOne(set utils.DBObject, id string) (util
|
||||
if code != 200 {
|
||||
return nil, code, err
|
||||
}
|
||||
fmt.Println("UPDATE", avoid, res.(*Workflow).ScheduleActive)
|
||||
if !avoid { // if the schedule is not avoided, update the executions
|
||||
if code, err := wfa.execution(id, res.(*Workflow), false); code != 200 {
|
||||
return nil, code, errors.New("could not update the executions : " + err.Error())
|
||||
if code, err := wfa.execution(id, res.(*Workflow), true); err != nil {
|
||||
return nil, code, err
|
||||
}
|
||||
}
|
||||
wfa.execute(res.(*Workflow), false, false) // update the workspace for the workflow
|
||||
wfa.execute(res.(*Workflow), false) // update the workspace for the workflow
|
||||
wfa.share(res.(*Workflow), false, wfa.Caller) // share the update to the peers
|
||||
return res, code, nil
|
||||
return res, code, err
|
||||
}
|
||||
|
||||
// StoreOne stores a workflow in the database
|
||||
func (wfa *workflowMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject, int, error) {
|
||||
res, code, err := wfa.GenericStoreOne(data, wfa)
|
||||
if err != nil || code != 200 {
|
||||
if err != nil {
|
||||
return nil, code, err
|
||||
}
|
||||
wfa.share(res.(*Workflow), false, wfa.Caller) // share the creation to the peers
|
||||
@ -263,8 +264,8 @@ func (wfa *workflowMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject,
|
||||
if code, err := wfa.execution(res.GetID(), res.(*Workflow), false); err != nil {
|
||||
return nil, code, err
|
||||
}
|
||||
wfa.execute(res.(*Workflow), false, false) // store the workspace for the workflow
|
||||
return res, code, nil
|
||||
wfa.execute(res.(*Workflow), false) // store the workspace for the workflow
|
||||
return res, code, err
|
||||
}
|
||||
|
||||
// CopyOne copies a workflow in the database
|
||||
@ -274,7 +275,7 @@ func (wfa *workflowMongoAccessor) CopyOne(data utils.DBObject) (utils.DBObject,
|
||||
|
||||
// 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
|
||||
func (wfa *workflowMongoAccessor) execute(workflow *Workflow, delete bool, active bool) {
|
||||
func (wfa *workflowMongoAccessor) execute(workflow *Workflow, delete bool) {
|
||||
|
||||
accessor := (&workspace.Workspace{}).GetAccessor(nil)
|
||||
filters := &dbs.Filters{
|
||||
@ -291,25 +292,25 @@ func (wfa *workflowMongoAccessor) execute(workflow *Workflow, delete bool, activ
|
||||
}
|
||||
if err == nil && len(resource) > 0 { // if the workspace already exists, update it
|
||||
accessor.UpdateOne(&workspace.Workspace{
|
||||
Active: active,
|
||||
Active: true,
|
||||
ResourceSet: resources.ResourceSet{
|
||||
Datas: workflow.Datas,
|
||||
Processings: workflow.Processings,
|
||||
Storages: workflow.Storages,
|
||||
Workflows: workflow.Workflows,
|
||||
Computes: workflow.Computes,
|
||||
Datacenters: workflow.Datacenters,
|
||||
},
|
||||
}, resource[0].GetID())
|
||||
} else { // if the workspace does not exist, create it
|
||||
accessor.StoreOne(&workspace.Workspace{
|
||||
Active: active,
|
||||
Active: true,
|
||||
AbstractObject: utils.AbstractObject{Name: workflow.Name + "_workspace"},
|
||||
ResourceSet: resources.ResourceSet{
|
||||
Datas: workflow.Datas,
|
||||
Processings: workflow.Processings,
|
||||
Storages: workflow.Storages,
|
||||
Workflows: workflow.Workflows,
|
||||
Computes: workflow.Computes,
|
||||
Datacenters: workflow.Datacenters,
|
||||
},
|
||||
})
|
||||
}
|
||||
@ -324,7 +325,7 @@ func (wfa *workflowMongoAccessor) LoadOne(id string) (utils.DBObject, int, error
|
||||
return nil, code, err
|
||||
}
|
||||
res_mongo.Decode(&workflow)
|
||||
wfa.execute(&workflow, false, true) // if no workspace is attached to the workflow, create it
|
||||
wfa.execute(&workflow, false) // if no workspace is attached to the workflow, create it
|
||||
|
||||
return &workflow, 200, nil
|
||||
}
|
||||
|
@ -18,7 +18,6 @@ const (
|
||||
STARTED
|
||||
FAILURE
|
||||
SUCCESS
|
||||
FORGOTTEN
|
||||
)
|
||||
|
||||
var str = [...]string{
|
||||
@ -26,7 +25,6 @@ var str = [...]string{
|
||||
"started",
|
||||
"failure",
|
||||
"success",
|
||||
"forgotten",
|
||||
}
|
||||
|
||||
func FromInt(i int) string {
|
||||
@ -80,15 +78,11 @@ func (dma *WorkflowExecutions) Serialize() map[string]interface{} {
|
||||
* workflows generate their own executions
|
||||
*/
|
||||
type WorkflowExecution struct {
|
||||
utils.AbstractObject // AbstractObject contains the basic fields of an object (id, name)
|
||||
ExecDate *time.Time `json:"execution_date,omitempty" bson:"execution_date,omitempty" validate:"required"` // ExecDate is the execution date of the workflow, is required
|
||||
EndDate *time.Time `json:"end_date,omitempty" bson:"end_date,omitempty"` // EndDate is the end date of the workflow
|
||||
State ScheduledType `json:"state" bson:"state" default:"0"` // State is the state 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
|
||||
utils.AbstractObject // AbstractObject contains the basic fields of an object (id, name)
|
||||
ExecDate *time.Time `json:"execution_date,omitempty" bson:"execution_date,omitempty" validate:"required"` // ExecDate is the execution date of the workflow, is required
|
||||
EndDate *time.Time `json:"end_date,omitempty" bson:"end_date,omitempty"` // EndDate is the end date of the workflow
|
||||
State int64 `json:"state,omitempty" bson:"state,omitempty"` // State is the state of the workflow
|
||||
WorkflowID string `json:"workflow_id" bson:"workflow_id,omitempty"` // WorkflowID is the ID of the workflow
|
||||
}
|
||||
|
||||
// tool to transform the argo status to a state
|
||||
@ -96,13 +90,13 @@ func (wfa *WorkflowExecution) ArgoStatusToState(status string) *WorkflowExecutio
|
||||
status = strings.ToLower(status)
|
||||
switch status {
|
||||
case "succeeded": // Succeeded
|
||||
wfa.State = SUCCESS
|
||||
wfa.State = int64(SUCCESS.EnumIndex())
|
||||
case "pending": // Pending
|
||||
wfa.State = SCHEDULED
|
||||
wfa.State = int64(SCHEDULED.EnumIndex())
|
||||
case "running": // Running
|
||||
wfa.State = STARTED
|
||||
wfa.State = int64(STARTED.EnumIndex())
|
||||
default: // Failed
|
||||
wfa.State = FAILURE
|
||||
wfa.State = int64(FAILURE.EnumIndex())
|
||||
}
|
||||
return wfa
|
||||
}
|
||||
@ -121,7 +115,7 @@ func (d *WorkflowExecution) GetName() string {
|
||||
|
||||
func (d *WorkflowExecution) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
|
||||
data := New() // Create a new instance of the accessor
|
||||
data.Init(tools.WORKFLOW_EXECUTION, caller) // Initialize the accessor with the WORKFLOW_EXECUTION model type
|
||||
data.Init(utils.WORKFLOW_EXECUTION, caller) // Initialize the accessor with the WORKFLOW_EXECUTION model type
|
||||
return data
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,6 @@
|
||||
package workflow_execution
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"cloud.o-forge.io/core/oc-lib/dbs"
|
||||
"cloud.o-forge.io/core/oc-lib/dbs/mongo"
|
||||
"cloud.o-forge.io/core/oc-lib/models/utils"
|
||||
@ -40,14 +38,10 @@ func (wfa *workflowExecutionMongoAccessor) LoadOne(id string) (utils.DBObject, i
|
||||
return nil, code, err
|
||||
}
|
||||
res_mongo.Decode(&workflow)
|
||||
if workflow.State == SCHEDULED && time.Now().UTC().After(*workflow.ExecDate) {
|
||||
workflow.State = FORGOTTEN
|
||||
wfa.GenericRawUpdateOne(&workflow, id, wfa)
|
||||
}
|
||||
return &workflow, 200, nil
|
||||
}
|
||||
|
||||
func (wfa *workflowExecutionMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int, error) {
|
||||
func (wfa workflowExecutionMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int, error) {
|
||||
objs := []utils.ShallowDBObject{}
|
||||
res_mongo, code, err := mongo.MONGOService.LoadAll(wfa.GetType())
|
||||
if err != nil {
|
||||
@ -59,10 +53,6 @@ func (wfa *workflowExecutionMongoAccessor) LoadAll() ([]utils.ShallowDBObject, i
|
||||
return nil, 404, err
|
||||
}
|
||||
for _, r := range results {
|
||||
if r.State == SCHEDULED && time.Now().UTC().After(*r.ExecDate) {
|
||||
r.State = FORGOTTEN
|
||||
wfa.GenericRawUpdateOne(&r, r.UUID, wfa)
|
||||
}
|
||||
objs = append(objs, &r.AbstractObject)
|
||||
}
|
||||
return objs, 200, nil
|
||||
@ -88,10 +78,6 @@ func (wfa *workflowExecutionMongoAccessor) Search(filters *dbs.Filters, search s
|
||||
return nil, 404, err
|
||||
}
|
||||
for _, r := range results {
|
||||
if r.State == SCHEDULED && time.Now().UTC().After(*r.ExecDate) {
|
||||
r.State = FORGOTTEN
|
||||
wfa.GenericRawUpdateOne(&r, r.UUID, wfa)
|
||||
}
|
||||
objs = append(objs, &r)
|
||||
}
|
||||
return objs, 200, nil
|
||||
|
@ -32,7 +32,7 @@ func (d *Rule) GetName() string {
|
||||
|
||||
func (d *Rule) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
|
||||
data := New()
|
||||
data.Init(tools.RULE, caller)
|
||||
data.Init(utils.RULE, caller)
|
||||
return data
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
package shallow_collaborative_area
|
||||
package shallow_shared_workspace
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
@ -8,7 +8,7 @@ import (
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type ShallowCollaborativeArea struct {
|
||||
type ShallowSharedWorkspace struct {
|
||||
utils.AbstractObject
|
||||
IsSent bool `json:"is_sent" bson:"-"`
|
||||
CreatorID string `json:"peer_id,omitempty" bson:"peer_id,omitempty" validate:"required"`
|
||||
@ -21,27 +21,27 @@ type ShallowCollaborativeArea struct {
|
||||
Rules []string `json:"rules,omitempty" bson:"rules,omitempty"`
|
||||
}
|
||||
|
||||
func (ao *ShallowCollaborativeArea) GetID() string {
|
||||
func (ao *ShallowSharedWorkspace) GetID() string {
|
||||
return ao.UUID
|
||||
}
|
||||
|
||||
func (r *ShallowCollaborativeArea) GenerateID() {
|
||||
func (r *ShallowSharedWorkspace) GenerateID() {
|
||||
if r.UUID == "" {
|
||||
r.UUID = uuid.New().String()
|
||||
}
|
||||
}
|
||||
|
||||
func (d *ShallowCollaborativeArea) GetName() string {
|
||||
func (d *ShallowSharedWorkspace) GetName() string {
|
||||
return d.Name
|
||||
}
|
||||
|
||||
func (d *ShallowCollaborativeArea) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
|
||||
func (d *ShallowSharedWorkspace) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
|
||||
data := New()
|
||||
data.Init(tools.COLLABORATIVE_AREA, caller)
|
||||
data.Init(utils.SHARED_WORKSPACE, caller)
|
||||
return data
|
||||
}
|
||||
|
||||
func (dma *ShallowCollaborativeArea) Deserialize(j map[string]interface{}) utils.DBObject {
|
||||
func (dma *ShallowSharedWorkspace) Deserialize(j map[string]interface{}) utils.DBObject {
|
||||
b, err := json.Marshal(j)
|
||||
if err != nil {
|
||||
return nil
|
||||
@ -50,7 +50,7 @@ func (dma *ShallowCollaborativeArea) Deserialize(j map[string]interface{}) utils
|
||||
return dma
|
||||
}
|
||||
|
||||
func (dma *ShallowCollaborativeArea) Serialize() map[string]interface{} {
|
||||
func (dma *ShallowSharedWorkspace) Serialize() map[string]interface{} {
|
||||
var m map[string]interface{}
|
||||
b, err := json.Marshal(dma)
|
||||
if err != nil {
|
@ -1,4 +1,4 @@
|
||||
package shallow_collaborative_area
|
||||
package shallow_shared_workspace
|
||||
|
||||
import (
|
||||
"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) {
|
||||
return wfa.GenericUpdateOne(set.(*ShallowCollaborativeArea), id, wfa, &ShallowCollaborativeArea{})
|
||||
return wfa.GenericUpdateOne(set.(*ShallowSharedWorkspace), id, wfa, &ShallowSharedWorkspace{})
|
||||
}
|
||||
|
||||
func (wfa *shallowSharedWorkspaceMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject, int, error) {
|
||||
return wfa.GenericStoreOne(data.(*ShallowCollaborativeArea), wfa)
|
||||
return wfa.GenericStoreOne(data.(*ShallowSharedWorkspace), wfa)
|
||||
}
|
||||
|
||||
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) {
|
||||
var sharedWorkspace ShallowCollaborativeArea
|
||||
var sharedWorkspace ShallowSharedWorkspace
|
||||
res_mongo, code, err := mongo.MONGOService.LoadOne(id, wfa.GetType())
|
||||
if err != nil {
|
||||
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())
|
||||
return nil, code, err
|
||||
}
|
||||
var results []ShallowCollaborativeArea
|
||||
var results []ShallowSharedWorkspace
|
||||
if err = res_mongo.All(mongo.MngoCtx, &results); err != nil {
|
||||
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())
|
||||
return nil, code, err
|
||||
}
|
||||
var results []ShallowCollaborativeArea
|
||||
var results []ShallowSharedWorkspace
|
||||
if err = res_mongo.All(mongo.MngoCtx, &results); err != nil {
|
||||
return nil, 404, err
|
||||
}
|
@ -1,13 +1,13 @@
|
||||
package collaborative_area
|
||||
package shared_workspace
|
||||
|
||||
import (
|
||||
"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/utils"
|
||||
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/shared/rules/rule"
|
||||
"cloud.o-forge.io/core/oc-lib/tools"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
@ -16,7 +16,7 @@ import (
|
||||
// WARNING : it got a shallow object version, this one is the full version
|
||||
// full version is the one used by API
|
||||
// other one is a shallow version used by the Lib for import cycle problem purposes
|
||||
type CollaborativeArea struct {
|
||||
type SharedWorkspace struct {
|
||||
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
|
||||
CreatorID string `json:"peer_id,omitempty" bson:"peer_id,omitempty" validate:"required"` // CreatorID is the ID of the creator
|
||||
@ -34,27 +34,27 @@ type CollaborativeArea struct {
|
||||
SharedPeers []*peer.Peer `json:"shared_peers,omitempty" bson:"-"` // SharedPeers is the shared peers of the workspace
|
||||
}
|
||||
|
||||
func (ao *CollaborativeArea) GetID() string {
|
||||
func (ao *SharedWorkspace) GetID() string {
|
||||
return ao.UUID
|
||||
}
|
||||
|
||||
func (r *CollaborativeArea) GenerateID() {
|
||||
func (r *SharedWorkspace) GenerateID() {
|
||||
if r.UUID == "" {
|
||||
r.UUID = uuid.New().String()
|
||||
}
|
||||
}
|
||||
|
||||
func (d *CollaborativeArea) GetName() string {
|
||||
func (d *SharedWorkspace) GetName() string {
|
||||
return d.Name
|
||||
}
|
||||
|
||||
func (d *CollaborativeArea) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
|
||||
data := New() // Create a new instance of the accessor
|
||||
data.Init(tools.COLLABORATIVE_AREA, caller) // Initialize the accessor with the SHARED_WORKSPACE model type
|
||||
func (d *SharedWorkspace) GetAccessor(caller *tools.HTTPCaller) utils.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
|
||||
return data
|
||||
}
|
||||
|
||||
func (dma *CollaborativeArea) Deserialize(j map[string]interface{}) utils.DBObject {
|
||||
func (dma *SharedWorkspace) Deserialize(j map[string]interface{}) utils.DBObject {
|
||||
b, err := json.Marshal(j)
|
||||
if err != nil {
|
||||
return nil
|
||||
@ -63,7 +63,7 @@ func (dma *CollaborativeArea) Deserialize(j map[string]interface{}) utils.DBObje
|
||||
return dma
|
||||
}
|
||||
|
||||
func (dma *CollaborativeArea) Serialize() map[string]interface{} {
|
||||
func (dma *SharedWorkspace) Serialize() map[string]interface{} {
|
||||
var m map[string]interface{}
|
||||
b, err := json.Marshal(dma)
|
||||
if err != nil {
|
@ -1,4 +1,4 @@
|
||||
package collaborative_area
|
||||
package shared_workspace
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@ -6,52 +6,53 @@ import (
|
||||
|
||||
"cloud.o-forge.io/core/oc-lib/dbs"
|
||||
"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/utils"
|
||||
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/shared/rules/rule"
|
||||
"cloud.o-forge.io/core/oc-lib/static"
|
||||
"cloud.o-forge.io/core/oc-lib/tools"
|
||||
)
|
||||
|
||||
// SharedWorkspace is a struct that represents a collaborative area
|
||||
type collaborativeAreaMongoAccessor struct {
|
||||
// SharedWorkspace is a struct that represents a shared workspace
|
||||
type sharedWorkspaceMongoAccessor struct {
|
||||
utils.AbstractAccessor // AbstractAccessor contains the basic fields of an accessor (model, caller)
|
||||
}
|
||||
|
||||
// New creates a new instance of the collaborativeAreaMongoAccessor
|
||||
func New() *collaborativeAreaMongoAccessor {
|
||||
return &collaborativeAreaMongoAccessor{}
|
||||
// New creates a new instance of the sharedWorkspaceMongoAccessor
|
||||
func New() *sharedWorkspaceMongoAccessor {
|
||||
return &sharedWorkspaceMongoAccessor{}
|
||||
}
|
||||
|
||||
// DeleteOne deletes a collaborative area from the database, given its ID, it automatically share to peers if the workspace is shared
|
||||
func (wfa *collaborativeAreaMongoAccessor) DeleteOne(id string) (utils.DBObject, int, error) {
|
||||
// DeleteOne deletes a shared workspace 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) {
|
||||
set, code, _ := wfa.LoadOne(id)
|
||||
if code == 200 { // always delete on peers than recreate
|
||||
wfa.deleteToPeer(set.(*CollaborativeArea))
|
||||
wfa.deleteToPeer(set.(*SharedWorkspace))
|
||||
}
|
||||
wfa.sharedWorkflow(&CollaborativeArea{}, id) // create all shared workflows
|
||||
wfa.sharedWorkspace(&CollaborativeArea{}, id) // create all collaborative areas
|
||||
return wfa.GenericDeleteOne(id, wfa) // then add on yours
|
||||
wfa.sharedWorkflow(&SharedWorkspace{}, id) // create all shared workflows
|
||||
wfa.sharedWorkspace(&SharedWorkspace{}, id) // create all shared workspaces
|
||||
return wfa.GenericDeleteOne(id, wfa) // then add on yours
|
||||
}
|
||||
|
||||
/*
|
||||
sharedWorkspace is a function that shares the collaborative area to the peers
|
||||
sharedWorkspace is a function that shares the shared workspace to the peers
|
||||
*/
|
||||
func (wfa *collaborativeAreaMongoAccessor) sharedWorkspace(shared *CollaborativeArea, id string) {
|
||||
func (wfa *sharedWorkspaceMongoAccessor) sharedWorkspace(shared *SharedWorkspace, id string) {
|
||||
eldest, code, _ := wfa.LoadOne(id) // get the eldest
|
||||
accessor := (&workspace.Workspace{}).GetAccessor(nil)
|
||||
if code == 200 {
|
||||
eld := eldest.(*CollaborativeArea)
|
||||
eld := eldest.(*SharedWorkspace)
|
||||
if eld.Workspaces != nil { // update all your workspaces in the eldest by replacing shared ref by an empty string
|
||||
for _, v := range eld.Workspaces {
|
||||
accessor.UpdateOne(&workspace.Workspace{Shared: ""}, v)
|
||||
if wfa.Caller != nil || wfa.Caller.URLS == nil || wfa.Caller.URLS[tools.WORKSPACE] == nil {
|
||||
if wfa.Caller != nil || wfa.Caller.URLS == nil || wfa.Caller.URLS[utils.WORKSPACE.String()] == nil {
|
||||
continue
|
||||
}
|
||||
paccess := (&peer.Peer{}) // send to all peers
|
||||
for _, p := range shared.Peers { // delete the collaborative area on the peer
|
||||
b, err := paccess.LaunchPeerExecution(p, v, tools.WORKSPACE, tools.DELETE, nil, wfa.Caller)
|
||||
for _, p := range shared.Peers { // delete the shared workspace on the peer
|
||||
b, err := paccess.LaunchPeerExecution(p, v, utils.WORKSPACE, tools.DELETE, nil, wfa.Caller)
|
||||
if err != nil && b == nil {
|
||||
wfa.Logger.Error().Msg("Could not send to peer " + p + ". Error: " + err.Error())
|
||||
}
|
||||
@ -60,19 +61,19 @@ func (wfa *collaborativeAreaMongoAccessor) sharedWorkspace(shared *Collaborative
|
||||
}
|
||||
}
|
||||
if shared.Workspaces != nil {
|
||||
for _, v := range shared.Workspaces { // update all the collaborative areas
|
||||
for _, v := range shared.Workspaces { // update all the shared workspaces
|
||||
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[tools.WORKSPACE] == nil {
|
||||
if wfa.Caller != nil || wfa.Caller.URLS == nil || wfa.Caller.URLS[utils.WORKSPACE.String()] == nil {
|
||||
continue
|
||||
}
|
||||
for _, p := range shared.Peers {
|
||||
if code != 200 {
|
||||
continue
|
||||
}
|
||||
paccess := (&peer.Peer{}) // send to all peers, add the collaborative area on the peer
|
||||
paccess := (&peer.Peer{}) // send to all peers, add the shared workspace on the peer
|
||||
s := workspace.Serialize()
|
||||
s["name"] = fmt.Sprintf("%v", s["name"]) + "_" + p
|
||||
b, err := paccess.LaunchPeerExecution(p, v, tools.WORKSPACE, tools.POST, s, wfa.Caller)
|
||||
b, err := paccess.LaunchPeerExecution(p, v, utils.WORKSPACE, tools.POST, s, wfa.Caller)
|
||||
if err != nil && b == nil {
|
||||
wfa.Logger.Error().Msg("Could not send to peer " + p + ". Error: " + err.Error())
|
||||
}
|
||||
@ -80,15 +81,15 @@ func (wfa *collaborativeAreaMongoAccessor) sharedWorkspace(shared *Collaborative
|
||||
}
|
||||
}
|
||||
// deleting on peers before adding, to avoid conflicts on peers side
|
||||
// because you have no reference to the remote collaborative area
|
||||
// because you have no reference to the remote shared workspace
|
||||
}
|
||||
|
||||
// sharedWorkflow is a function that shares the shared workflow to the peers
|
||||
func (wfa *collaborativeAreaMongoAccessor) sharedWorkflow(shared *CollaborativeArea, id string) {
|
||||
func (wfa *sharedWorkspaceMongoAccessor) sharedWorkflow(shared *SharedWorkspace, id string) {
|
||||
accessor := (&w.Workflow{}).GetAccessor(nil)
|
||||
eldest, code, _ := wfa.LoadOne(id) // get the eldest
|
||||
if code == 200 {
|
||||
eld := eldest.(*CollaborativeArea)
|
||||
eld := eldest.(*SharedWorkspace)
|
||||
if eld.Workflows != nil {
|
||||
for _, v := range eld.Workflows {
|
||||
data, code, _ := accessor.LoadOne(v)
|
||||
@ -103,12 +104,12 @@ func (wfa *collaborativeAreaMongoAccessor) sharedWorkflow(shared *CollaborativeA
|
||||
n := &w.Workflow{}
|
||||
n.Shared = new
|
||||
accessor.UpdateOne(n, v)
|
||||
if wfa.Caller != nil || wfa.Caller.URLS == nil || wfa.Caller.URLS[tools.WORKFLOW] == nil {
|
||||
if wfa.Caller != nil || wfa.Caller.URLS == nil || wfa.Caller.URLS[utils.WORKFLOW.String()] == nil {
|
||||
continue
|
||||
}
|
||||
paccess := (&peer.Peer{}) // send to all peers
|
||||
for _, p := range shared.Peers { // delete the shared workflow on the peer
|
||||
b, err := paccess.LaunchPeerExecution(p, v, tools.WORKFLOW, tools.DELETE, nil, wfa.Caller)
|
||||
b, err := paccess.LaunchPeerExecution(p, v, utils.WORKFLOW, tools.DELETE, nil, wfa.Caller)
|
||||
if err != nil && b == nil {
|
||||
wfa.Logger.Error().Msg("Could not send to peer " + p + ". Error: " + err.Error())
|
||||
}
|
||||
@ -125,7 +126,7 @@ func (wfa *collaborativeAreaMongoAccessor) sharedWorkflow(shared *CollaborativeA
|
||||
if !slices.Contains(s.Shared, id) {
|
||||
s.Shared = append(s.Shared, id)
|
||||
workflow, code, _ := accessor.UpdateOne(s, v)
|
||||
if wfa.Caller != nil || wfa.Caller.URLS == nil || wfa.Caller.URLS[tools.WORKFLOW] == nil {
|
||||
if wfa.Caller != nil || wfa.Caller.URLS == nil || wfa.Caller.URLS[utils.WORKFLOW.String()] == nil {
|
||||
continue
|
||||
}
|
||||
paccess := (&peer.Peer{})
|
||||
@ -133,7 +134,7 @@ func (wfa *collaborativeAreaMongoAccessor) sharedWorkflow(shared *CollaborativeA
|
||||
if code == 200 {
|
||||
s := workflow.Serialize() // add the shared workflow on the peer
|
||||
s["name"] = fmt.Sprintf("%v", s["name"]) + "_" + p
|
||||
b, err := paccess.LaunchPeerExecution(p, shared.UUID, tools.WORKFLOW, tools.POST, s, wfa.Caller)
|
||||
b, err := paccess.LaunchPeerExecution(p, shared.UUID, utils.WORKFLOW, tools.POST, s, wfa.Caller)
|
||||
if err != nil && b == nil {
|
||||
wfa.Logger.Error().Msg("Could not send to peer " + p + ". Error: " + err.Error())
|
||||
}
|
||||
@ -147,85 +148,85 @@ func (wfa *collaborativeAreaMongoAccessor) sharedWorkflow(shared *CollaborativeA
|
||||
// because you have no reference to the remote shared workflow
|
||||
}
|
||||
|
||||
// sharedWorkspace is a function that shares the collaborative area to the peers
|
||||
func (wfa *collaborativeAreaMongoAccessor) deleteToPeer(shared *CollaborativeArea) {
|
||||
if wfa.Caller == nil || wfa.Caller.URLS == nil || wfa.Caller.URLS[tools.COLLABORATIVE_AREA] == nil || wfa.Caller.Disabled {
|
||||
// sharedWorkspace is a function that shares the shared workspace to the peers
|
||||
func (wfa *sharedWorkspaceMongoAccessor) deleteToPeer(shared *SharedWorkspace) {
|
||||
if wfa.Caller == nil || wfa.Caller.URLS == nil || wfa.Caller.URLS[utils.SHARED_WORKSPACE.String()] == nil {
|
||||
return
|
||||
}
|
||||
paccess := (&peer.Peer{})
|
||||
for _, v := range shared.Peers {
|
||||
if ok, _ := (&peer.Peer{AbstractObject: utils.AbstractObject{UUID: v}}).IsMySelf(); ok {
|
||||
if (&peer.Peer{AbstractObject: utils.AbstractObject{UUID: v}}).IsMySelf() {
|
||||
continue
|
||||
}
|
||||
b, err := paccess.LaunchPeerExecution(v, shared.UUID, tools.COLLABORATIVE_AREA, tools.DELETE, nil, wfa.Caller)
|
||||
b, err := paccess.LaunchPeerExecution(v, shared.UUID, utils.SHARED_WORKSPACE, tools.DELETE, nil, wfa.Caller)
|
||||
if err != nil && b == nil {
|
||||
wfa.Logger.Error().Msg("Could not send to peer " + v + ". Error: " + err.Error())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// sharedWorkspace is a function that shares the collaborative area to the peers
|
||||
func (wfa *collaborativeAreaMongoAccessor) sendToPeer(shared *CollaborativeArea) {
|
||||
if wfa.Caller == nil || wfa.Caller.URLS == nil || wfa.Caller.URLS[tools.COLLABORATIVE_AREA] == nil || wfa.Caller.Disabled {
|
||||
// sharedWorkspace is a function that shares the shared workspace to the peers
|
||||
func (wfa *sharedWorkspaceMongoAccessor) sendToPeer(shared *SharedWorkspace) {
|
||||
if wfa.Caller == nil || wfa.Caller.URLS == nil || wfa.Caller.URLS[utils.SHARED_WORKSPACE.String()] == nil {
|
||||
return
|
||||
}
|
||||
|
||||
paccess := (&peer.Peer{})
|
||||
for _, v := range shared.Peers {
|
||||
if ok, _ := (&peer.Peer{AbstractObject: utils.AbstractObject{UUID: v}}).IsMySelf(); ok || shared.IsSent {
|
||||
if (&peer.Peer{AbstractObject: utils.AbstractObject{UUID: v}}).IsMySelf() || shared.IsSent {
|
||||
continue
|
||||
}
|
||||
shared.IsSent = true
|
||||
b, err := paccess.LaunchPeerExecution(v, v, tools.COLLABORATIVE_AREA, tools.POST, shared.Serialize(), wfa.Caller)
|
||||
b, err := paccess.LaunchPeerExecution(v, v, utils.SHARED_WORKSPACE, tools.POST, shared.Serialize(), wfa.Caller)
|
||||
if err != nil && b == nil {
|
||||
wfa.Logger.Error().Msg("Could not send to peer " + v + ". Error: " + err.Error())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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 *collaborativeAreaMongoAccessor) UpdateOne(set utils.DBObject, id string) (utils.DBObject, int, error) {
|
||||
res, code, err := wfa.GenericUpdateOne(set.(*CollaborativeArea), id, wfa, &CollaborativeArea{})
|
||||
wfa.deleteToPeer(res.(*CollaborativeArea)) // delete the collaborative area on the peer
|
||||
wfa.sharedWorkflow(res.(*CollaborativeArea), id) // replace all shared workflows
|
||||
wfa.sharedWorkspace(res.(*CollaborativeArea), id) // replace all collaborative areas (not shared worspace obj but workspace one)
|
||||
wfa.sendToPeer(res.(*CollaborativeArea)) // send the collaborative area (collaborative area object) to the peers
|
||||
// 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
|
||||
func (wfa *sharedWorkspaceMongoAccessor) UpdateOne(set utils.DBObject, id string) (utils.DBObject, int, error) {
|
||||
res, code, err := wfa.GenericUpdateOne(set.(*SharedWorkspace), id, wfa, &SharedWorkspace{})
|
||||
wfa.deleteToPeer(res.(*SharedWorkspace)) // delete the shared workspace on the peer
|
||||
wfa.sharedWorkflow(res.(*SharedWorkspace), id) // replace all shared workflows
|
||||
wfa.sharedWorkspace(res.(*SharedWorkspace), id) // replace all shared workspaces (not shared worspace obj but workspace one)
|
||||
wfa.sendToPeer(res.(*SharedWorkspace)) // send the shared workspace (shared workspace object) to the peers
|
||||
return res, code, err
|
||||
}
|
||||
|
||||
// StoreOne stores a collaborative area in the database, it automatically share to peers if the workspace is shared
|
||||
func (wfa *collaborativeAreaMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject, int, error) {
|
||||
_, id := (&peer.Peer{}).IsMySelf() // get the local peer
|
||||
data.(*CollaborativeArea).CreatorID = id // set the creator id
|
||||
data.(*CollaborativeArea).Peers = append(data.(*CollaborativeArea).Peers, id) // add the creator id to the peers
|
||||
// StoreOne stores a shared workspace in the database, it automatically share to peers if the workspace is shared
|
||||
func (wfa *sharedWorkspaceMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject, int, error) {
|
||||
id, _ := static.GetMyLocalJsonPeer() // get the local peer
|
||||
data.(*SharedWorkspace).CreatorID = id // set the creator id
|
||||
data.(*SharedWorkspace).Peers = append(data.(*SharedWorkspace).Peers, id) // add the creator id to the peers
|
||||
// then reset the shared fields
|
||||
if data.(*CollaborativeArea).Workspaces == nil {
|
||||
data.(*CollaborativeArea).Workspaces = []string{}
|
||||
if data.(*SharedWorkspace).Workspaces == nil {
|
||||
data.(*SharedWorkspace).Workspaces = []string{}
|
||||
}
|
||||
if data.(*CollaborativeArea).Workflows == nil {
|
||||
data.(*CollaborativeArea).Workflows = []string{}
|
||||
if data.(*SharedWorkspace).Workflows == nil {
|
||||
data.(*SharedWorkspace).Workflows = []string{}
|
||||
}
|
||||
if data.(*CollaborativeArea).Rules == nil {
|
||||
data.(*CollaborativeArea).Rules = []string{}
|
||||
if data.(*SharedWorkspace).Rules == nil {
|
||||
data.(*SharedWorkspace).Rules = []string{}
|
||||
}
|
||||
|
||||
d, code, err := wfa.GenericStoreOne(data.(*CollaborativeArea), wfa)
|
||||
d, code, err := wfa.GenericStoreOne(data.(*SharedWorkspace), wfa)
|
||||
|
||||
if code == 200 {
|
||||
wfa.sharedWorkflow(d.(*CollaborativeArea), d.GetID()) // create all shared workflows
|
||||
wfa.sharedWorkspace(d.(*CollaborativeArea), d.GetID()) // create all collaborative areas
|
||||
wfa.sendToPeer(d.(*CollaborativeArea)) // send the collaborative area (collaborative area object) to the peers
|
||||
wfa.sharedWorkflow(d.(*SharedWorkspace), d.GetID()) // create all shared workflows
|
||||
wfa.sharedWorkspace(d.(*SharedWorkspace), d.GetID()) // create all shared workspaces
|
||||
wfa.sendToPeer(d.(*SharedWorkspace)) // send the shared workspace (shared workspace object) to the peers
|
||||
}
|
||||
return data, code, err
|
||||
}
|
||||
|
||||
// CopyOne copies a CollaborativeArea in the database
|
||||
func (wfa *collaborativeAreaMongoAccessor) CopyOne(data utils.DBObject) (utils.DBObject, int, error) {
|
||||
// CopyOne copies a shared workspace in the database
|
||||
func (wfa *sharedWorkspaceMongoAccessor) CopyOne(data utils.DBObject) (utils.DBObject, int, error) {
|
||||
return wfa.StoreOne(data)
|
||||
}
|
||||
|
||||
// enrich is a function that enriches the CollaborativeArea with the shared objects
|
||||
func (wfa *collaborativeAreaMongoAccessor) enrich(sharedWorkspace *CollaborativeArea) *CollaborativeArea {
|
||||
// enrich is a function that enriches the shared workspace with the shared objects
|
||||
func (wfa *sharedWorkspaceMongoAccessor) enrich(sharedWorkspace *SharedWorkspace) *SharedWorkspace {
|
||||
access := (&workspace.Workspace{}).GetAccessor(nil)
|
||||
res, code, _ := access.Search(&dbs.Filters{
|
||||
Or: map[string][]dbs.Filter{
|
||||
@ -273,38 +274,38 @@ func (wfa *collaborativeAreaMongoAccessor) enrich(sharedWorkspace *Collaborative
|
||||
return sharedWorkspace
|
||||
}
|
||||
|
||||
// LoadOne loads a collaborative area from the database, given its ID and enrich it
|
||||
func (wfa *collaborativeAreaMongoAccessor) LoadOne(id string) (utils.DBObject, int, error) {
|
||||
var sharedWorkspace CollaborativeArea
|
||||
// LoadOne loads a shared workspace from the database, given its ID and enrich it
|
||||
func (wfa *sharedWorkspaceMongoAccessor) LoadOne(id string) (utils.DBObject, int, error) {
|
||||
var sharedWorkspace SharedWorkspace
|
||||
res_mongo, code, err := mongo.MONGOService.LoadOne(id, wfa.GetType())
|
||||
if err != nil {
|
||||
wfa.Logger.Error().Msg("Could not retrieve " + id + " from db. Error: " + err.Error())
|
||||
return nil, code, err
|
||||
}
|
||||
res_mongo.Decode(&sharedWorkspace)
|
||||
return wfa.enrich(&sharedWorkspace), 200, nil // enrich the collaborative area
|
||||
return wfa.enrich(&sharedWorkspace), 200, nil // enrich the shared workspace
|
||||
}
|
||||
|
||||
// LoadAll loads all the collaborative areas from the database and enrich them
|
||||
func (wfa collaborativeAreaMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int, error) {
|
||||
// LoadAll loads all the shared workspaces from the database and enrich them
|
||||
func (wfa sharedWorkspaceMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int, error) {
|
||||
objs := []utils.ShallowDBObject{}
|
||||
res_mongo, code, err := mongo.MONGOService.LoadAll(wfa.GetType())
|
||||
if err != nil {
|
||||
wfa.Logger.Error().Msg("Could not retrieve any from db. Error: " + err.Error())
|
||||
return nil, code, err
|
||||
}
|
||||
var results []CollaborativeArea
|
||||
var results []SharedWorkspace
|
||||
if err = res_mongo.All(mongo.MngoCtx, &results); err != nil {
|
||||
return nil, 404, err
|
||||
}
|
||||
for _, r := range results {
|
||||
objs = append(objs, wfa.enrich(&r)) // enrich the collaborative area
|
||||
objs = append(objs, wfa.enrich(&r)) // enrich the shared workspace
|
||||
}
|
||||
return objs, 200, nil
|
||||
}
|
||||
|
||||
// Search searches for collaborative areas in the database, given some filters OR a search string
|
||||
func (wfa *collaborativeAreaMongoAccessor) Search(filters *dbs.Filters, search string) ([]utils.ShallowDBObject, int, error) {
|
||||
// Search searches for shared workspaces in the database, given some filters OR a search string
|
||||
func (wfa *sharedWorkspaceMongoAccessor) Search(filters *dbs.Filters, search string) ([]utils.ShallowDBObject, int, error) {
|
||||
objs := []utils.ShallowDBObject{}
|
||||
if (filters == nil || len(filters.And) == 0 || len(filters.Or) == 0) && search != "" {
|
||||
filters = &dbs.Filters{
|
||||
@ -318,12 +319,12 @@ func (wfa *collaborativeAreaMongoAccessor) Search(filters *dbs.Filters, search s
|
||||
wfa.Logger.Error().Msg("Could not store to db. Error: " + err.Error())
|
||||
return nil, code, err
|
||||
}
|
||||
var results []CollaborativeArea
|
||||
var results []SharedWorkspace
|
||||
if err = res_mongo.All(mongo.MngoCtx, &results); err != nil {
|
||||
return nil, 404, err
|
||||
}
|
||||
for _, r := range results {
|
||||
objs = append(objs, wfa.enrich(&r)) // enrich the collaborative area
|
||||
objs = append(objs, wfa.enrich(&r)) // enrich the shared workspace
|
||||
}
|
||||
return objs, 200, nil
|
||||
}
|
@ -12,7 +12,7 @@ import (
|
||||
// Workspace is a struct that represents a workspace
|
||||
type Workspace struct {
|
||||
utils.AbstractObject // AbstractObject contains the basic fields of an object (id, name)
|
||||
resources.ResourceSet // ResourceSet contains the resources of the workspace (data, compute, processing, storage, workflow)
|
||||
resources.ResourceSet // ResourceSet contains the resources of the workspace (data, datacenter, processing, storage, workflow)
|
||||
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
|
||||
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 {
|
||||
data := New() // Create a new instance of the accessor
|
||||
data.Init(tools.WORKSPACE, caller) // Initialize the accessor with the WORKSPACE model type
|
||||
data.Init(utils.WORKSPACE, caller) // Initialize the accessor with the WORKSPACE model type
|
||||
return data
|
||||
}
|
||||
|
||||
|
@ -1,34 +0,0 @@
|
||||
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/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/resources/data"
|
||||
"cloud.o-forge.io/core/oc-lib/models/resources/compute"
|
||||
"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/storage"
|
||||
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/workspace/shared/shallow_shared_workspace"
|
||||
"cloud.o-forge.io/core/oc-lib/tools"
|
||||
)
|
||||
|
||||
@ -30,9 +30,7 @@ func New() *workspaceMongoAccessor {
|
||||
// it checks if a workspace with the same name already exists
|
||||
func (wfa *workspaceMongoAccessor) DeleteOne(id string) (utils.DBObject, int, error) {
|
||||
res, code, err := wfa.GenericDeleteOne(id, wfa)
|
||||
if code == 200 && res != nil {
|
||||
wfa.share(res.(*Workspace), tools.DELETE, wfa.Caller) // Share the deletion to the peers
|
||||
}
|
||||
wfa.share(res.(*Workspace), true, wfa.Caller) // Share the deletion to the peers
|
||||
return res, code, err
|
||||
}
|
||||
|
||||
@ -40,7 +38,7 @@ func (wfa *workspaceMongoAccessor) DeleteOne(id string) (utils.DBObject, int, er
|
||||
func (wfa *workspaceMongoAccessor) UpdateOne(set utils.DBObject, id string) (utils.DBObject, int, error) {
|
||||
d := set.(*Workspace) // Get the workspace from the set
|
||||
d.DataResources = nil // Reset the resources
|
||||
d.ComputeResources = nil
|
||||
d.DatacenterResources = nil
|
||||
d.StorageResources = nil
|
||||
d.ProcessingResources = nil
|
||||
d.WorkflowResources = nil
|
||||
@ -56,9 +54,7 @@ func (wfa *workspaceMongoAccessor) UpdateOne(set utils.DBObject, id string) (uti
|
||||
}
|
||||
}
|
||||
res, code, err := wfa.GenericUpdateOne(set, id, wfa, &Workspace{})
|
||||
if code == 200 && res != nil {
|
||||
wfa.share(res.(*Workspace), tools.PUT, wfa.Caller)
|
||||
}
|
||||
wfa.share(res.(*Workspace), false, wfa.Caller)
|
||||
return res, code, err
|
||||
}
|
||||
|
||||
@ -76,7 +72,7 @@ func (wfa *workspaceMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject
|
||||
// reset the resources
|
||||
d := data.(*Workspace)
|
||||
d.DataResources = nil
|
||||
d.ComputeResources = nil
|
||||
d.DatacenterResources = nil
|
||||
d.StorageResources = nil
|
||||
d.ProcessingResources = nil
|
||||
d.WorkflowResources = nil
|
||||
@ -102,13 +98,13 @@ func (wfa *workspaceMongoAccessor) fill(workflow *Workspace) *Workspace {
|
||||
}
|
||||
}
|
||||
}
|
||||
// Fill the workspace with the computes
|
||||
if workflow.Computes != nil && len(workflow.Computes) > 0 {
|
||||
dataAccessor := (&compute.ComputeResource{}).GetAccessor(nil)
|
||||
for _, id := range workflow.Computes {
|
||||
// Fill the workspace with the datacenters
|
||||
if workflow.Datacenters != nil && len(workflow.Datacenters) > 0 {
|
||||
dataAccessor := (&datacenter.DatacenterResource{}).GetAccessor(nil)
|
||||
for _, id := range workflow.Datacenters {
|
||||
d, _, e := dataAccessor.LoadOne(id)
|
||||
if e == nil {
|
||||
workflow.ComputeResources = append(workflow.ComputeResources, d.(*compute.ComputeResource))
|
||||
workflow.DatacenterResources = append(workflow.DatacenterResources, d.(*datacenter.DatacenterResource))
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -204,28 +200,26 @@ func (wfa *workspaceMongoAccessor) Search(filters *dbs.Filters, search string) (
|
||||
/*
|
||||
This function is used to share the workspace with the peers
|
||||
*/
|
||||
func (wfa *workspaceMongoAccessor) share(realData *Workspace, method tools.METHOD, caller *tools.HTTPCaller) {
|
||||
if realData.Shared == "" || caller.Disabled {
|
||||
func (wfa *workspaceMongoAccessor) share(realData *Workspace, delete bool, caller *tools.HTTPCaller) {
|
||||
if realData.Shared == "" {
|
||||
return
|
||||
}
|
||||
access := (&shallow_collaborative_area.ShallowCollaborativeArea{}).GetAccessor(nil)
|
||||
access := (&shallow_shared_workspace.ShallowSharedWorkspace{}).GetAccessor(nil)
|
||||
res, code, _ := access.LoadOne(realData.Shared)
|
||||
if code != 200 {
|
||||
return
|
||||
}
|
||||
var err error
|
||||
paccess := &peer.Peer{}
|
||||
for _, p := range res.(*shallow_collaborative_area.ShallowCollaborativeArea).Peers {
|
||||
for _, p := range res.(*shallow_shared_workspace.ShallowSharedWorkspace).Peers {
|
||||
paccess.UUID = p
|
||||
if ok, _ := paccess.IsMySelf(); ok { // If the peer is the current peer, never share because it will create a loop
|
||||
if paccess.IsMySelf() { // If the peer is the current peer, never share because it will create a loop
|
||||
continue
|
||||
}
|
||||
if method == tools.DELETE { // If the workspace is deleted, share the deletion
|
||||
history := NewHistory()
|
||||
history.StoreOne(history.MapFromWorkspace(res.(*Workspace)))
|
||||
_, err = paccess.LaunchPeerExecution(p, res.GetID(), tools.WORKSPACE, tools.DELETE, map[string]interface{}{}, caller)
|
||||
if delete { // If the workspace is deleted, share the deletion
|
||||
_, err = paccess.LaunchPeerExecution(p, res.GetID(), utils.WORKSPACE, tools.DELETE, map[string]interface{}{}, caller)
|
||||
} else { // If the workspace is updated, share the update
|
||||
_, err = paccess.LaunchPeerExecution(p, res.GetID(), tools.WORKSPACE, tools.PUT, res.Serialize(), caller)
|
||||
_, err = paccess.LaunchPeerExecution(p, res.GetID(), utils.WORKSPACE, tools.PUT, res.Serialize(), caller)
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
|
30
static/peer_static.go
Normal file
30
static/peer_static.go
Normal file
@ -0,0 +1,30 @@
|
||||
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",
|
||||
}
|
||||
}
|
Binary file not shown.
Before Width: | Height: | Size: 665 B |
Binary file not shown.
Before Width: | Height: | Size: 628 B |
@ -1,60 +0,0 @@
|
||||
<!-- 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>
|
@ -1,79 +0,0 @@
|
||||
<!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>
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
51
tools/api.go
51
tools/api.go
@ -3,12 +3,9 @@ package tools
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"cloud.o-forge.io/core/oc-lib/config"
|
||||
"cloud.o-forge.io/core/oc-lib/dbs/mongo"
|
||||
beego "github.com/beego/beego/v2/server/web"
|
||||
)
|
||||
|
||||
/*
|
||||
@ -52,16 +49,6 @@ func (s State) String() string {
|
||||
|
||||
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
|
||||
func (a *API) GetState() (State, int, error) {
|
||||
// Check if the database is up
|
||||
@ -83,34 +70,12 @@ func (a *API) GetState() (State, int, error) {
|
||||
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
|
||||
func (a *API) CheckRemotePeer(url string) (State, map[string]int) {
|
||||
// Check if the database is up
|
||||
caller := NewHTTPCaller(map[DataType]map[METHOD]string{}) // Create a new http caller
|
||||
caller := NewHTTPCaller(map[string]map[METHOD]string{}) // Create a new http caller
|
||||
var resp APIStatusResponse
|
||||
b, err := caller.CallPost(url, "", map[string]interface{}{}) // Call the status endpoint of the peer
|
||||
b, err := caller.CallPost(url, "/status", map[string]interface{}{}) // Call the status endpoint of the peer
|
||||
if err != nil {
|
||||
return DEAD, map[string]int{} // If the peer is not reachable, return dead
|
||||
}
|
||||
@ -126,29 +91,27 @@ func (a *API) CheckRemotePeer(url string) (State, map[string]int) {
|
||||
}
|
||||
|
||||
// CheckRemoteAPIs checks the state of remote APIs from your proper OC
|
||||
func (a *API) CheckRemoteAPIs(apis []DataType) (State, map[string]string, error) {
|
||||
func (a *API) CheckRemoteAPIs(urls map[string]string) (State, map[string]string, error) {
|
||||
// Check if the database is up
|
||||
new := map[string]string{}
|
||||
caller := NewHTTPCaller(map[DataType]map[METHOD]string{}) // Create a new http caller
|
||||
caller := NewHTTPCaller(map[string]map[METHOD]string{}) // Create a new http caller
|
||||
code := 0
|
||||
e := ""
|
||||
state := ALIVE
|
||||
reachable := false
|
||||
for _, api := range apis { // Check the state of each remote API in the list
|
||||
for appName, url := range urls { // Check the state of each remote API in the list
|
||||
var resp APIStatusResponse
|
||||
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)
|
||||
b, err := caller.CallGet(url, "/version/status") // Call the status endpoint of the remote API (standard OC status endpoint)
|
||||
if err != nil {
|
||||
state = REDUCED_SERVICE // If a remote API is not reachable, return reduced service
|
||||
continue
|
||||
}
|
||||
json.Unmarshal(b, &resp)
|
||||
fmt.Println(string(b))
|
||||
if resp.Data == nil { //
|
||||
state = REDUCED_SERVICE // If the response is empty, return reduced service
|
||||
continue
|
||||
}
|
||||
new[api.String()] = resp.Data.State
|
||||
new[appName] = resp.Data.State
|
||||
if resp.Data.Code > code {
|
||||
code = resp.Data.Code
|
||||
e += resp.Error
|
||||
|
@ -5,7 +5,6 @@ import (
|
||||
"strings"
|
||||
|
||||
"cloud.o-forge.io/core/oc-lib/config"
|
||||
"cloud.o-forge.io/core/oc-lib/logs"
|
||||
"github.com/nats-io/nats.go"
|
||||
)
|
||||
|
||||
@ -15,7 +14,6 @@ type NATSMethod int
|
||||
const (
|
||||
REMOVE NATSMethod = iota
|
||||
CREATE
|
||||
DISCOVERY
|
||||
)
|
||||
|
||||
// NameToMethod returns the NATSMethod enum value from a string
|
||||
@ -45,33 +43,6 @@ func NewNATSCaller() *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
|
||||
func (o *natsCaller) SetNATSPub(dataName string, method NATSMethod, data interface{}) string {
|
||||
if config.GetConfig().NATSUrl == "" {
|
||||
|
@ -5,8 +5,6 @@ import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// HTTP Method Enum defines the different methods that can be used to interact with the HTTP server
|
||||
@ -17,16 +15,11 @@ const (
|
||||
PUT
|
||||
POST
|
||||
DELETE
|
||||
|
||||
STRICT_INTERNAL_GET
|
||||
STRICT_INTERNAL_PUT
|
||||
STRICT_INTERNAL_POST
|
||||
STRICT_INTERNAL_DELETE
|
||||
)
|
||||
|
||||
// String returns the string of the enum
|
||||
func (m METHOD) String() string {
|
||||
return [...]string{"GET", "PUT", "POST", "DELETE", "INTERNALGET", "INTERNALPUT", "INTERNALPOST", "INTERNALDELETE"}[m]
|
||||
return [...]string{"GET", "PUT", "POST", "DELETE"}[m]
|
||||
}
|
||||
|
||||
// EnumIndex returns the index of the enum
|
||||
@ -36,8 +29,7 @@ func (m METHOD) EnumIndex() int {
|
||||
|
||||
// ToMethod returns the method from a string
|
||||
func ToMethod(str string) METHOD {
|
||||
for _, s := range []METHOD{GET, PUT, POST, DELETE,
|
||||
STRICT_INTERNAL_GET, STRICT_INTERNAL_PUT, STRICT_INTERNAL_POST, STRICT_INTERNAL_DELETE} {
|
||||
for _, s := range []METHOD{GET, PUT, POST, DELETE} {
|
||||
if s.String() == str {
|
||||
return s
|
||||
}
|
||||
@ -48,29 +40,19 @@ func ToMethod(str string) METHOD {
|
||||
var HTTPCallerInstance = &HTTPCaller{} // Singleton instance of the HTTPCaller
|
||||
|
||||
type HTTPCaller struct {
|
||||
URLS map[DataType]map[METHOD]string // Map of the different methods and their urls
|
||||
Disabled bool // Disabled flag
|
||||
URLS map[string]map[METHOD]string // Map of the different methods and their urls
|
||||
}
|
||||
|
||||
// NewHTTPCaller creates a new instance of the HTTP Caller
|
||||
func NewHTTPCaller(urls map[DataType]map[METHOD]string) *HTTPCaller {
|
||||
func NewHTTPCaller(urls map[string]map[METHOD]string) *HTTPCaller {
|
||||
return &HTTPCaller{
|
||||
URLS: urls, // Set the urls defined in the config & based on the data name type & method
|
||||
Disabled: false,
|
||||
URLS: urls, // Set the urls defined in the config & based on the data name type & method
|
||||
}
|
||||
}
|
||||
|
||||
// CallGet calls the GET method on the HTTP server
|
||||
func (caller *HTTPCaller) CallGet(url string, subpath string, types ...string) ([]byte, error) {
|
||||
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)
|
||||
func (caller *HTTPCaller) CallGet(url string, subpath string) ([]byte, error) {
|
||||
resp, err := http.Get(url + subpath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -81,7 +63,7 @@ func (caller *HTTPCaller) CallGet(url string, subpath string, types ...string) (
|
||||
// CallPut calls the DELETE method on the HTTP server
|
||||
func (caller *HTTPCaller) CallDelete(url string, subpath string) ([]byte, error) {
|
||||
resp, err := http.NewRequest("DELETE", url+subpath, nil)
|
||||
if err != nil || resp == nil || resp.Body == nil {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
@ -89,32 +71,10 @@ func (caller *HTTPCaller) CallDelete(url string, subpath string) ([]byte, error)
|
||||
}
|
||||
|
||||
// CallPost calls the POST method on the HTTP server
|
||||
func (caller *HTTPCaller) CallPost(url string, subpath string, body map[string]interface{}, types ...string) ([]byte, error) {
|
||||
func (caller *HTTPCaller) CallPost(url string, subpath string, body map[string]interface{}) ([]byte, error) {
|
||||
postBody, _ := json.Marshal(body)
|
||||
responseBody := bytes.NewBuffer(postBody)
|
||||
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)
|
||||
resp, err := http.Post(url+subpath, "application/json", responseBody)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -122,40 +82,4 @@ func (caller *HTTPCaller) CallPut(url string, subpath string, body map[string]in
|
||||
return io.ReadAll(resp.Body)
|
||||
}
|
||||
|
||||
// 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)
|
||||
}
|
||||
// NO PUT IN HERE TO DANGEROUS TO USE ON A REMOTE SERVER, MAYBE NEEDED IN THE FUTURE
|
||||
|
Loading…
Reference in New Issue
Block a user