From 15c71171456cd61063f61923c3661a260415a4b9 Mon Sep 17 00:00:00 2001 From: 6092002067 Date: Tue, 14 Feb 2017 10:50:45 +0800 Subject: [PATCH] Add module holms-actions code Issue-ID:HOLMES-9 Change-Id: Ied3ccef8a873bf4b9af0a0fc12324fb69716bc18 Signed-off-by: 6092002067 --- License.txt | 1005 ++++++++++++++++++++ holmes-actions/pom.xml | 112 +++ .../common/api/AlarmsCorrelationDbService.java | 33 + .../common/api/AlarmsCorrelationMqService.java | 39 + .../common/api/entity/AlarmsCorrelation.java | 53 ++ .../common/api/entity/AlarmsCorrelationFilter.java | 38 + .../common/api/entity/CorrelationResult.java | 43 + .../holmes/common/api/entity/CorrelationRule.java | 61 ++ .../org/openo/holmes/common/api/stat/Alarm.java | 322 +++++++ .../openo/holmes/common/api/stat/AplusData.java | 43 + .../openo/holmes/common/api/stat/AplusResult.java | 66 ++ .../openo/holmes/common/constant/AlarmConst.java | 117 +++ .../holmes/common/constant/MicroServiceConst.java | 28 + .../holmes/common/db/AlarmCorrelationQueryDao.java | 57 ++ .../holmes/common/db/AlarmsCorrelationDao.java | 36 + .../common/db/mapper/AlarmsCorrelationMapper.java | 86 ++ .../holmes/common/exception/CallException.java | 26 + .../common/exception/DataFormatException.java | 26 + .../openo/holmes/common/exception/DbException.java | 28 + .../holmes/common/exception/EngineException.java | 32 + .../common/exception/RuleIllegalityException.java | 32 + .../holmes/common/i18n/correlation-i18n-en-US.json | 29 + .../holmes/common/i18n/correlation-i18n-zh-CN.json | 25 + .../i18n/correlation-operationcode-i18n-en-US.json | 87 ++ .../i18n/correlation-operationcode-i18n-zh-CN.json | 87 ++ .../holmes/common/utils/DateForJsonSerializer.java | 37 + .../org/openo/holmes/common/utils/DbDaoUtil.java | 93 ++ .../org/openo/holmes/common/utils/JacksonUtil.java | 55 ++ .../openo/holmes/common/utils/JudgeNullUtil.java | 49 + .../openo/holmes/common/utils/LanguageUtil.java | 53 ++ .../org/openo/holmes/common/utils/UserUtil.java | 35 + pom.xml | 137 +++ 32 files changed, 2970 insertions(+) create mode 100644 License.txt create mode 100644 holmes-actions/pom.xml create mode 100644 holmes-actions/src/main/java/org/openo/holmes/common/api/AlarmsCorrelationDbService.java create mode 100644 holmes-actions/src/main/java/org/openo/holmes/common/api/AlarmsCorrelationMqService.java create mode 100644 holmes-actions/src/main/java/org/openo/holmes/common/api/entity/AlarmsCorrelation.java create mode 100644 holmes-actions/src/main/java/org/openo/holmes/common/api/entity/AlarmsCorrelationFilter.java create mode 100644 holmes-actions/src/main/java/org/openo/holmes/common/api/entity/CorrelationResult.java create mode 100644 holmes-actions/src/main/java/org/openo/holmes/common/api/entity/CorrelationRule.java create mode 100644 holmes-actions/src/main/java/org/openo/holmes/common/api/stat/Alarm.java create mode 100644 holmes-actions/src/main/java/org/openo/holmes/common/api/stat/AplusData.java create mode 100644 holmes-actions/src/main/java/org/openo/holmes/common/api/stat/AplusResult.java create mode 100644 holmes-actions/src/main/java/org/openo/holmes/common/constant/AlarmConst.java create mode 100644 holmes-actions/src/main/java/org/openo/holmes/common/constant/MicroServiceConst.java create mode 100644 holmes-actions/src/main/java/org/openo/holmes/common/db/AlarmCorrelationQueryDao.java create mode 100644 holmes-actions/src/main/java/org/openo/holmes/common/db/AlarmsCorrelationDao.java create mode 100644 holmes-actions/src/main/java/org/openo/holmes/common/db/mapper/AlarmsCorrelationMapper.java create mode 100644 holmes-actions/src/main/java/org/openo/holmes/common/exception/CallException.java create mode 100644 holmes-actions/src/main/java/org/openo/holmes/common/exception/DataFormatException.java create mode 100644 holmes-actions/src/main/java/org/openo/holmes/common/exception/DbException.java create mode 100644 holmes-actions/src/main/java/org/openo/holmes/common/exception/EngineException.java create mode 100644 holmes-actions/src/main/java/org/openo/holmes/common/exception/RuleIllegalityException.java create mode 100644 holmes-actions/src/main/java/org/openo/holmes/common/i18n/correlation-i18n-en-US.json create mode 100644 holmes-actions/src/main/java/org/openo/holmes/common/i18n/correlation-i18n-zh-CN.json create mode 100644 holmes-actions/src/main/java/org/openo/holmes/common/i18n/correlation-operationcode-i18n-en-US.json create mode 100644 holmes-actions/src/main/java/org/openo/holmes/common/i18n/correlation-operationcode-i18n-zh-CN.json create mode 100644 holmes-actions/src/main/java/org/openo/holmes/common/utils/DateForJsonSerializer.java create mode 100644 holmes-actions/src/main/java/org/openo/holmes/common/utils/DbDaoUtil.java create mode 100644 holmes-actions/src/main/java/org/openo/holmes/common/utils/JacksonUtil.java create mode 100644 holmes-actions/src/main/java/org/openo/holmes/common/utils/JudgeNullUtil.java create mode 100644 holmes-actions/src/main/java/org/openo/holmes/common/utils/LanguageUtil.java create mode 100644 holmes-actions/src/main/java/org/openo/holmes/common/utils/UserUtil.java create mode 100644 pom.xml diff --git a/License.txt b/License.txt new file mode 100644 index 0000000..5bc2ac6 --- /dev/null +++ b/License.txt @@ -0,0 +1,1005 @@ + + + + + License.txt - Release - Open-O Wiki + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+
+
+
+ +
+
+ + + + + + + + + + +
+
+
+ +
Page tree
+ + +
+ + + +
    +
    +
    +
+ + +
+
+ +
+
+ + + + +
+
+ + + + +
+ + + + + Skip to end of banner +
+ + + + + +Go to start of banner +
+ + +

+ License.txt +

+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+
+ + + + + + + + + + + + + + + + + + Skip to end of metadata +
+ + + + +Go to start of metadata +
+ + + +
+ +

THIS LICENSE FILE CONTAINS THE LICENSE APPLICABLE DEPENDING ON THE TYPE OF CONTRIBUTIONS.

APACHE LICENSE 2 IS APPLICABLE FOR SOURCE CODE, CREATIVE COMMONS ATTRIBUTION 4.0 INTERNATIONAL FOR DOCUMENTATION

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/

TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION

1. Definitions.

"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.

"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.

"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.

"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.

"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.

"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.

"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).

"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.

"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."

"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.

2. Grant of Copyright License.

Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.

3. Grant of Patent License.

Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.

4. Redistribution.

You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:

You must give any other recipients of the Work or Derivative Works a copy of this License; and
You must cause any modified files to carry prominent notices stating that You changed the files; and
You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.

5. Submission of Contributions.

Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.

6. Trademarks.

This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.

7. Disclaimer of Warranty.

Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.

8. Limitation of Liability.

In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.

9. Accepting Warranty or Additional Liability.

While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.

END OF TERMS AND CONDITIONS

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Attribution 4.0 International

https://creativecommons.org/licenses/by/4.0/legalcode

---------------------------------------------------------------------------------------

Creative Commons Corporation ("Creative Commons") is not a law firm and
does not provide legal services or legal advice. Distribution of
Creative Commons public licenses does not create a lawyer-client or
other relationship. Creative Commons makes its licenses and related
information available on an "as-is" basis. Creative Commons gives no
warranties regarding its licenses, any material licensed under their
terms and conditions, or any related information. Creative Commons
disclaims all liability for damages resulting from their use to the
fullest extent possible.

Using Creative Commons Public Licenses

Creative Commons public licenses provide a standard set of terms and
conditions that creators and other rights holders may use to share
original works of authorship and other material subject to copyright
and certain other rights specified in the public license below. The
following considerations are for informational purposes only, are not
exhaustive, and do not form part of our licenses.

Considerations for licensors: Our public licenses are
intended for use by those authorized to give the public
permission to use material in ways otherwise restricted by
copyright and certain other rights. Our licenses are
irrevocable. Licensors should read and understand the terms
and conditions of the license they choose before applying it.
Licensors should also secure all rights necessary before
applying our licenses so that the public can reuse the
material as expected. Licensors should clearly mark any
material not subject to the license. This includes other CC-
licensed material, or material used under an exception or
limitation to copyright. More considerations for licensors:
wiki.creativecommons.org/Considerations_for_licensors

Considerations for the public: By using one of our public
licenses, a licensor grants the public permission to use the
licensed material under specified terms and conditions. If
the licensor's permission is not necessary for any reason--for
example, because of any applicable exception or limitation to
copyright--then that use is not regulated by the license. Our
licenses grant only permissions under copyright and certain
other rights that a licensor has authority to grant. Use of
the licensed material may still be restricted for other
reasons, including because others have copyright or other
rights in the material. A licensor may make special requests,
such as asking that all changes be marked or described.
Although not required by our licenses, you are encouraged to
respect those requests where reasonable. More_considerations
for the public:
wiki.creativecommons.org/Considerations_for_licensees

---------------------------------------------------------------------------------------

Creative Commons Attribution 4.0 International Public License

By exercising the Licensed Rights (defined below), You accept and agree
to be bound by the terms and conditions of this Creative Commons
Attribution 4.0 International Public License ("Public License"). To the
extent this Public License may be interpreted as a contract, You are
granted the Licensed Rights in consideration of Your acceptance of
these terms and conditions, and the Licensor grants You such rights in
consideration of benefits the Licensor receives from making the
Licensed Material available under these terms and conditions.


Section 1 -- Definitions.

a. Adapted Material means material subject to Copyright and Similar
Rights that is derived from or based upon the Licensed Material
and in which the Licensed Material is translated, altered,
arranged, transformed, or otherwise modified in a manner requiring
permission under the Copyright and Similar Rights held by the
Licensor. For purposes of this Public License, where the Licensed
Material is a musical work, performance, or sound recording,
Adapted Material is always produced where the Licensed Material is
synched in timed relation with a moving image.

b. Adapter's License means the license You apply to Your Copyright
and Similar Rights in Your contributions to Adapted Material in
accordance with the terms and conditions of this Public License.

c. Copyright and Similar Rights means copyright and/or similar rights
closely related to copyright including, without limitation,
performance, broadcast, sound recording, and Sui Generis Database
Rights, without regard to how the rights are labeled or
categorized. For purposes of this Public License, the rights
specified in Section 2(b)(1)-(2) are not Copyright and Similar
Rights.

d. Effective Technological Measures means those measures that, in the
absence of proper authority, may not be circumvented under laws
fulfilling obligations under Article 11 of the WIPO Copyright
Treaty adopted on December 20, 1996, and/or similar international
agreements.

e. Exceptions and Limitations means fair use, fair dealing, and/or
any other exception or limitation to Copyright and Similar Rights
that applies to Your use of the Licensed Material.

f. Licensed Material means the artistic or literary work, database,
or other material to which the Licensor applied this Public
License.

g. Licensed Rights means the rights granted to You subject to the
terms and conditions of this Public License, which are limited to
all Copyright and Similar Rights that apply to Your use of the
Licensed Material and that the Licensor has authority to license.

h. Licensor means the individual(s) or entity(ies) granting rights
under this Public License.

i. Share means to provide material to the public by any means or
process that requires permission under the Licensed Rights, such
as reproduction, public display, public performance, distribution,
dissemination, communication, or importation, and to make material
available to the public including in ways that members of the
public may access the material from a place and at a time
individually chosen by them.

j. Sui Generis Database Rights means rights other than copyright
resulting from Directive 96/9/EC of the European Parliament and of
the Council of 11 March 1996 on the legal protection of databases,
as amended and/or succeeded, as well as other essentially
equivalent rights anywhere in the world.

k. You means the individual or entity exercising the Licensed Rights
under this Public License. Your has a corresponding meaning.


Section 2 -- Scope.

a. License grant.

1. Subject to the terms and conditions of this Public License,
the Licensor hereby grants You a worldwide, royalty-free,
non-sublicensable, non-exclusive, irrevocable license to
exercise the Licensed Rights in the Licensed Material to:

a. reproduce and Share the Licensed Material, in whole or
in part; and

b. produce, reproduce, and Share Adapted Material.

2. Exceptions and Limitations. For the avoidance of doubt, where
Exceptions and Limitations apply to Your use, this Public
License does not apply, and You do not need to comply with
its terms and conditions.

3. Term. The term of this Public License is specified in Section
6(a).

4. Media and formats; technical modifications allowed. The
Licensor authorizes You to exercise the Licensed Rights in
all media and formats whether now known or hereafter created,
and to make technical modifications necessary to do so. The
Licensor waives and/or agrees not to assert any right or
authority to forbid You from making technical modifications
necessary to exercise the Licensed Rights, including
technical modifications necessary to circumvent Effective
Technological Measures. For purposes of this Public License,
simply making modifications authorized by this Section 2(a)
(4) never produces Adapted Material.

5. Downstream recipients.

a. Offer from the Licensor -- Licensed Material. Every
recipient of the Licensed Material automatically
receives an offer from the Licensor to exercise the
Licensed Rights under the terms and conditions of this
Public License.

b. No downstream restrictions. You may not offer or impose
any additional or different terms or conditions on, or
apply any Effective Technological Measures to, the
Licensed Material if doing so restricts exercise of the
Licensed Rights by any recipient of the Licensed
Material.

6. No endorsement. Nothing in this Public License constitutes or
may be construed as permission to assert or imply that You
are, or that Your use of the Licensed Material is, connected
with, or sponsored, endorsed, or granted official status by,
the Licensor or others designated to receive attribution as
provided in Section 3(a)(1)(A)(i).

b. Other rights.

1. Moral rights, such as the right of integrity, are not
licensed under this Public License, nor are publicity,
privacy, and/or other similar personality rights; however, to
the extent possible, the Licensor waives and/or agrees not to
assert any such rights held by the Licensor to the limited
extent necessary to allow You to exercise the Licensed
Rights, but not otherwise.

2. Patent and trademark rights are not licensed under this
Public License.

3. To the extent possible, the Licensor waives any right to
collect royalties from You for the exercise of the Licensed
Rights, whether directly or through a collecting society
under any voluntary or waivable statutory or compulsory
licensing scheme. In all other cases the Licensor expressly
reserves any right to collect such royalties.


Section 3 -- License Conditions.

Your exercise of the Licensed Rights is expressly made subject to the
following conditions.

a. Attribution.

1. If You Share the Licensed Material (including in modified
form), You must:

a. retain the following if it is supplied by the Licensor
with the Licensed Material:

i. identification of the creator(s) of the Licensed
Material and any others designated to receive
attribution, in any reasonable manner requested by
the Licensor (including by pseudonym if
designated);

ii. a copyright notice;

iii. a notice that refers to this Public License;

iv. a notice that refers to the disclaimer of
warranties;

v. a URI or hyperlink to the Licensed Material to the
extent reasonably practicable;

b. indicate if You modified the Licensed Material and
retain an indication of any previous modifications; and

c. indicate the Licensed Material is licensed under this
Public License, and include the text of, or the URI or
hyperlink to, this Public License.

2. You may satisfy the conditions in Section 3(a)(1) in any
reasonable manner based on the medium, means, and context in
which You Share the Licensed Material. For example, it may be
reasonable to satisfy the conditions by providing a URI or
hyperlink to a resource that includes the required
information.

3. If requested by the Licensor, You must remove any of the
information required by Section 3(a)(1)(A) to the extent
reasonably practicable.

4. If You Share Adapted Material You produce, the Adapter's
License You apply must not prevent recipients of the Adapted
Material from complying with this Public License.


Section 4 -- Sui Generis Database Rights.

Where the Licensed Rights include Sui Generis Database Rights that
apply to Your use of the Licensed Material:

a. for the avoidance of doubt, Section 2(a)(1) grants You the right
to extract, reuse, reproduce, and Share all or a substantial
portion of the contents of the database;

b. if You include all or a substantial portion of the database
contents in a database in which You have Sui Generis Database
Rights, then the database in which You have Sui Generis Database
Rights (but not its individual contents) is Adapted Material; and

c. You must comply with the conditions in Section 3(a) if You Share
all or a substantial portion of the contents of the database.

For the avoidance of doubt, this Section 4 supplements and does not
replace Your obligations under this Public License where the Licensed
Rights include other Copyright and Similar Rights.


Section 5 -- Disclaimer of Warranties and Limitation of Liability.

a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE
EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS
AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF
ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS,
IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION,
WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS,
ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT
KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT
ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU.

b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE
TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION,
NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT,
INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES,
COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR
USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN
ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR
DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR
IN PART, THIS LIMITATION MAY NOT APPLY TO YOU.

c. The disclaimer of warranties and limitation of liability provided
above shall be interpreted in a manner that, to the extent
possible, most closely approximates an absolute disclaimer and
waiver of all liability.


Section 6 -- Term and Termination.

a. This Public License applies for the term of the Copyright and
Similar Rights licensed here. However, if You fail to comply with
this Public License, then Your rights under this Public License
terminate automatically.

b. Where Your right to use the Licensed Material has terminated under
Section 6(a), it reinstates:

1. automatically as of the date the violation is cured, provided
it is cured within 30 days of Your discovery of the
violation; or

2. upon express reinstatement by the Licensor.

For the avoidance of doubt, this Section 6(b) does not affect any
right the Licensor may have to seek remedies for Your violations
of this Public License.

c. For the avoidance of doubt, the Licensor may also offer the
Licensed Material under separate terms or conditions or stop
distributing the Licensed Material at any time; however, doing so
will not terminate this Public License.

d. Sections 1, 5, 6, 7, and 8 survive termination of this Public
License.


Section 7 -- Other Terms and Conditions.

a. The Licensor shall not be bound by any additional or different
terms or conditions communicated by You unless expressly agreed.

b. Any arrangements, understandings, or agreements regarding the
Licensed Material not stated herein are separate from and
independent of the terms and conditions of this Public License.


Section 8 -- Interpretation.

a. For the avoidance of doubt, this Public License does not, and
shall not be interpreted to, reduce, limit, restrict, or impose
conditions on any use of the Licensed Material that could lawfully
be made without permission under this Public License.

b. To the extent possible, if any provision of this Public License is
deemed unenforceable, it shall be automatically reformed to the
minimum extent necessary to make it enforceable. If the provision
cannot be reformed, it shall be severed from this Public License
without affecting the enforceability of the remaining terms and
conditions.

c. No term or condition of this Public License will be waived and no
failure to comply consented to unless expressly agreed to by the
Licensor.

d. Nothing in this Public License constitutes or may be interpreted
as a limitation upon, or waiver of, any privileges and immunities
that apply to the Licensor or You, including from the legal
processes of any jurisdiction or authority.

---------------------------------------------------------------------------------------

Creative Commons is not a party to its public
licenses. Notwithstanding, Creative Commons may elect to apply one of
its public licenses to material it publishes and in those instances
will be considered the "Licensor." The text of the Creative Commons
public licenses is dedicated to the public domain under the CC0 Public
Domain Dedication. Except for the limited purpose of indicating that
material is shared under a Creative Commons public license or as
otherwise permitted by the Creative Commons policies published at
creativecommons.org/policies, Creative Commons does not authorize the
use of the trademark "Creative Commons" or any other trademark or logo
of Creative Commons without its prior written consent including,
without limitation, in connection with any unauthorized modifications
to any of its public licenses or any other arrangements,
understandings, or agreements concerning use of licensed material. For
the avoidance of doubt, this paragraph does not form part of the
public licenses.

Creative Commons may be contacted at creativecommons.org.

+ + + + +
+ + + + + + + + +
+ +
+ + + + + + + + + + + + + + + + + + + +
+ + + + +
+ + + + + + + + +
Write a comment…
+ +
+ +
+

+ Add Comment +

+
+
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + +
+ +
+
+ + + + + + + + diff --git a/holmes-actions/pom.xml b/holmes-actions/pom.xml new file mode 100644 index 0000000..e8725f3 --- /dev/null +++ b/holmes-actions/pom.xml @@ -0,0 +1,112 @@ + + + + 4.0.0 + + + org.openo.holmes + holmes-actions-parent + 1.1.0-SNAPSHOT + + + holmes-actions-service + jar + holmes-actions + + + + + + + org.antlr + stringtemplate + + + io.dropwizard + dropwizard-core + + + io.swagger + swagger-jersey2-jaxrs + + + org.projectlombok + lombok + + + mysql + mysql-connector-java + + + io.dropwizard + dropwizard-jdbi + + + org.quartz-scheduler + quartz + + + junit + junit + + + org.hamcrest + hamcrest-core + + + org.powermock + powermock-module-junit4 + + + io.dropwizard + dropwizard-jdbi + + + + org.apache.poi + poi + 3.10.1 + + + org.jdom + jdom + + + org.openo.common-services.common-utilities + dropwizard-ioc-container + + + + + + src/main/java + + **/*.properties + **/*.json + + + + src/main/resources + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.3 + + 1.8 + 1.8 + + + + + + diff --git a/holmes-actions/src/main/java/org/openo/holmes/common/api/AlarmsCorrelationDbService.java b/holmes-actions/src/main/java/org/openo/holmes/common/api/AlarmsCorrelationDbService.java new file mode 100644 index 0000000..4057c03 --- /dev/null +++ b/holmes-actions/src/main/java/org/openo/holmes/common/api/AlarmsCorrelationDbService.java @@ -0,0 +1,33 @@ +/** + * Copyright 2017 ZTE Corporation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.openo.holmes.common.api; + +import java.util.List; +import org.jvnet.hk2.annotations.Contract; +import org.openo.holmes.common.api.entity.AlarmsCorrelation; +import org.openo.holmes.common.api.entity.AlarmsCorrelationFilter; +import org.openo.holmes.common.exception.DbException; + +@Contract +public interface AlarmsCorrelationDbService { + + public void saveAlarmsCorrelation(AlarmsCorrelation alarmsCorrelation) throws DbException; + + public List queryAlarmsCorrelationByFilter( + AlarmsCorrelationFilter alarmsCorrelationFilter) throws DbException; + + public List queryAllAlarmsCorrelation(); +} diff --git a/holmes-actions/src/main/java/org/openo/holmes/common/api/AlarmsCorrelationMqService.java b/holmes-actions/src/main/java/org/openo/holmes/common/api/AlarmsCorrelationMqService.java new file mode 100644 index 0000000..8d34e3e --- /dev/null +++ b/holmes-actions/src/main/java/org/openo/holmes/common/api/AlarmsCorrelationMqService.java @@ -0,0 +1,39 @@ +/** + * Copyright 2017 ZTE Corporation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.openo.holmes.common.api; + +import org.jvnet.hk2.annotations.Contract; +import org.openo.holmes.common.api.stat.Alarm; + +@Contract +public interface AlarmsCorrelationMqService { + + public static final String MQ_TOPIC_NAME_ALARMS_CORRELATION = + "topic://voss/fm/alarms_correlation"; + + public static final String MQ_QUEUE_NAME_ALARMS_CORRELATION = + "queue://voss/fm/alarms_correlation"; + + public static final String MQ_TOPIC_NAME_ALARM = "topic://voss/fm/alarm"; + + public boolean sendMQTopicMsg(String ruleId, long createTimeL, Alarm parentAlarm, + Alarm childAlarm); + + public boolean sendMQTopicMsg(Alarm alarm); + + public boolean sendMQQueueMsg(String ruleId, long createTimeL, Alarm parentAlarm, + Alarm childAlarm); +} diff --git a/holmes-actions/src/main/java/org/openo/holmes/common/api/entity/AlarmsCorrelation.java b/holmes-actions/src/main/java/org/openo/holmes/common/api/entity/AlarmsCorrelation.java new file mode 100644 index 0000000..de1005c --- /dev/null +++ b/holmes-actions/src/main/java/org/openo/holmes/common/api/entity/AlarmsCorrelation.java @@ -0,0 +1,53 @@ +/** + * Copyright 2017 ZTE Corporation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.openo.holmes.common.api.entity; + +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.Date; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +public class AlarmsCorrelation { + + @JsonProperty(value = "ruleid") + private String ruleId; + + @JsonProperty(value = "ruleinfo") + private String ruleInfo; + + @JsonProperty(value = "resulttype") + private byte resultType; + + @JsonProperty(value = "createtime") + private Date createTime; + + @JsonProperty(value = "parentalarmid") + private long parentAlarmId; + + @JsonProperty(value = "childalarmid") + private long childAlarmId; + + @JsonProperty(defaultValue = "-1") + private long reserve1 = -1; + + @JsonProperty(defaultValue = "-1") + private long reserve2 = -1; + + @JsonProperty(defaultValue = "-1") + private long reserve3 = -1; +} diff --git a/holmes-actions/src/main/java/org/openo/holmes/common/api/entity/AlarmsCorrelationFilter.java b/holmes-actions/src/main/java/org/openo/holmes/common/api/entity/AlarmsCorrelationFilter.java new file mode 100644 index 0000000..bdbc02c --- /dev/null +++ b/holmes-actions/src/main/java/org/openo/holmes/common/api/entity/AlarmsCorrelationFilter.java @@ -0,0 +1,38 @@ +/** + * Copyright 2017 ZTE Corporation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.openo.holmes.common.api.entity; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +public class AlarmsCorrelationFilter { + + @JsonProperty(value = "ruleid") + private String ruleId; + + @JsonProperty(value = "parentalarmid") + private long parentAlarmId; + + @JsonProperty(value = "childalarmid") + private long childAlarmId; + + @JsonProperty(value = "where") + private String where; +} diff --git a/holmes-actions/src/main/java/org/openo/holmes/common/api/entity/CorrelationResult.java b/holmes-actions/src/main/java/org/openo/holmes/common/api/entity/CorrelationResult.java new file mode 100644 index 0000000..da6924b --- /dev/null +++ b/holmes-actions/src/main/java/org/openo/holmes/common/api/entity/CorrelationResult.java @@ -0,0 +1,43 @@ +/** + * Copyright 2017 ZTE Corporation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.openo.holmes.common.api.entity; + +import com.fasterxml.jackson.annotation.JsonProperty; +import org.openo.holmes.common.api.stat.Alarm; + +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +@Setter +@Getter +@NoArgsConstructor +@ToString +public class CorrelationResult { + + @JsonProperty + private String ruleId; + + @JsonProperty + private long createTimeL; + + @JsonProperty + private byte resultType; + + @JsonProperty + private Alarm[] affectedAlarms; +} diff --git a/holmes-actions/src/main/java/org/openo/holmes/common/api/entity/CorrelationRule.java b/holmes-actions/src/main/java/org/openo/holmes/common/api/entity/CorrelationRule.java new file mode 100644 index 0000000..4524d39 --- /dev/null +++ b/holmes-actions/src/main/java/org/openo/holmes/common/api/entity/CorrelationRule.java @@ -0,0 +1,61 @@ +/** + * Copyright 2017 ZTE Corporation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.openo.holmes.common.api.entity; + +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.Date; +import java.util.Properties; +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class CorrelationRule { + + @JsonProperty(value = "ruleid") + private String rid; + @JsonProperty(value = "rulename") + private String name; + @JsonProperty + private String description; + @JsonProperty + private int enabled; + @JsonProperty + private int templateID; + private String engineId; + @JsonProperty + private String engineType; + @JsonProperty + private String creator; + @JsonProperty + private String modifier; + @JsonProperty + private Properties params; + @JsonProperty + private String domain; + @JsonProperty + private String content; + @JsonProperty + private int isManual; + @JsonProperty + private String vendor; + @JsonProperty(value = "createtime") + private Date createTime; + @JsonProperty(value = "updatetime") + private Date updateTime; + @JsonProperty(value = "package") + private String packageName; +} diff --git a/holmes-actions/src/main/java/org/openo/holmes/common/api/stat/Alarm.java b/holmes-actions/src/main/java/org/openo/holmes/common/api/stat/Alarm.java new file mode 100644 index 0000000..71a5d00 --- /dev/null +++ b/holmes-actions/src/main/java/org/openo/holmes/common/api/stat/Alarm.java @@ -0,0 +1,322 @@ +/** + * Copyright 2017 ZTE Corporation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.openo.holmes.common.api.stat; + +import java.io.StringReader; +import java.lang.reflect.Field; +import java.util.Date; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import lombok.Getter; +import lombok.Setter; +import org.jdom.Attribute; +import org.jdom.Element; +import org.jdom.input.SAXBuilder; +import org.jdom.output.XMLOutputter; + + +@Getter +@Setter +public class Alarm implements AplusData, Cloneable { + + public static final byte EVENT_CLEARED_ALARM = 3; + + public static final byte EVENT_CHANGED = 2; + + public static final byte EVENT_CLEARED = 1; + + public static final byte EVENT_RAISED = 0; + + private static final long serialVersionUID = 4520003737132012000L; + + private byte eventType = EVENT_RAISED; + + private long id = 0L; + + private String alarmKey = ""; + + private String network = ""; + + private String neType = ""; + + private String equipType = ""; + + private String position1 = ""; + + private String subPosition1 = null; + + private String position2 = null; + + private String subPosition2 = null; + + private byte severity = -1; + + private byte alarmType = -1; + + private long probableCause = -1; + + private String specificProblem = null; + + private String additionalText = null; + + private Date raisedTime = new Date(); + + private Date raisedServerTime = new Date(); + + private Date clearedTime = null; + + private final Date clearedServerTime = null; + + private String region = null; + + private String site = null; + + private String aid = null; + + private short systemType = -1; + + private boolean rootAlarmFlag = false; + + private int linkId = -1; + + private int nodeIdx = -1; + + private Set linkIds = new HashSet(); + + private HashMap priorityMap = new HashMap(); + + private HashMap rootAlarmTypeMap = new HashMap(); + + private int rootAlarmType = -1; + + private boolean keyAlarmFlag = false; + + private int keyAlarmType = -1; + + private int networkLevel = -1; + + private int linkType = -1; + + private int centerType; + + private final Map linkIdNodeIdxMap = new HashMap(); + + public void addLinkIdNodeIdx(int linkId, int index) { + linkIdNodeIdxMap.put(linkId, index); + } + + /** + * Comparison of the location of different links: 999 the same link: the location of the node + * number less than otherIdIdx in the location of the number (in the otherIdIdx upstream):-1, + * the same link: the node position number is equal to the number of position in the otherIdIdx + * (in the same site otherIdIdx):0, the same link: the node location number is greater than the + * number of locations in otherIdIdx (otherIdIdx) with the site):1, + */ + public int CompareLinkPosition(Map otherIdIdx) { + Set myIdSet = new HashSet(); + myIdSet.addAll(this.linkIdNodeIdxMap.keySet()); + myIdSet.retainAll(otherIdIdx.keySet()); + + if (myIdSet.isEmpty()) { + return 999; + } + + for (int tempLinkId : myIdSet) { + return this.linkIdNodeIdxMap.get(tempLinkId) - otherIdIdx.get(tempLinkId); + } + return 999; + } + + public Map getLinkIdNodeIdx() { + return this.linkIdNodeIdxMap; + } + + public boolean containNode(int linkId, int index) { + if (linkIdNodeIdxMap.containsKey(linkId) && linkIdNodeIdxMap.get(linkId) == index) { + return true; + } else { + return false; + } + } + + @Override + public byte getDataType() { + return APLUS_EVENT; + } + + @Override + public String toString() { + final String nullStr = ""; + + Element el = new Element("Alarm"); + el.setAttribute("id", String.valueOf(id)); + el.setAttribute("aid", String.valueOf(aid)); + el.setAttribute("alarmKey", String.valueOf(alarmKey)); + el.setAttribute("eventType", String.valueOf(eventType)); + el.setAttribute("region", region == null ? nullStr : region); + el.setAttribute("site", site == null ? nullStr : site); + el.setAttribute("network", network); + el.setAttribute("neType", neType); + el.setAttribute("equipType", equipType); + el.setAttribute("position1", position1); + el.setAttribute("subPosition1", subPosition1 == null ? nullStr : subPosition1); + el.setAttribute("position2", position2 == null ? nullStr : position2); + el.setAttribute("subPosition2", subPosition2 == null ? nullStr : subPosition2); + el.setAttribute("severity", String.valueOf(severity)); + el.setAttribute("alarmType", String.valueOf(alarmType)); + el.setAttribute("probableCause", String.valueOf(probableCause)); + el.setAttribute("specificProblem", specificProblem == null ? nullStr : specificProblem); + el.setAttribute("additionalText", additionalText == null ? nullStr : additionalText); + el.setAttribute("raisedTime", String.valueOf(raisedTime.getTime())); + el.setAttribute("raisedServerTime", String.valueOf(raisedServerTime.getTime())); + if (clearedTime != null) { + el.setAttribute("clearedTime", String.valueOf(clearedTime.getTime())); + } + if (clearedServerTime != null) { + el.setAttribute("clearedServerTime", String.valueOf(clearedServerTime.getTime())); + } + + return new XMLOutputter().outputString(el); + } + + public static Alarm valueOf(String xmlString) { + Element element = null; + try { + StringReader sb = new StringReader(xmlString); + element = new SAXBuilder().build(sb).getRootElement(); + sb.close(); + } catch (Exception e) { + throw new RuntimeException(e); + } + + Alarm alarm = new Alarm(); + @SuppressWarnings("unchecked") + List list = element.getAttributes(); + for (Attribute attr : list) { + String attrName = attr.getName(); + try { + Field field = Alarm.class.getDeclaredField(attrName); + if (!attrName.endsWith("Time")) { + String type = field.getType().getSimpleName(); + if (type.equals("byte")) { + field.set(alarm, Byte.parseByte(attr.getValue())); + } else if (type.equals("long")) { + field.set(alarm, Long.parseLong(attr.getValue())); + } else if (type.equals("String")) { + field.set(alarm, attr.getValue()); + } else { + throw new RuntimeException("unknow attr type: " + type.toString()); + } + } else { + Date date = new Date(); + date.setTime(Long.parseLong(attr.getValue())); + field.set(alarm, date); + } + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + return alarm; + } + + @Override + public int hashCode() { + return this.getAlarmKey().hashCode(); + } + + @Override + public boolean equals(Object arg0) { + if (arg0 == null) { + return false; + } + return this.alarmKey.equals(((Alarm) arg0).getAlarmKey()); + } + + @Override + public Object clone() throws CloneNotSupportedException { + super.clone(); + + Alarm alarm = new Alarm(); + + alarm.setEventType(this.getEventType()); + + alarm.setAid(this.getAid()); + alarm.setId(this.getId()); + alarm.setAlarmKey(this.getAlarmKey()); + + alarm.setNetwork(this.getNetwork()); + alarm.setEquipType(this.getEquipType()); + alarm.setNeType(this.getNeType()); + alarm.setPosition1(this.getPosition1()); + alarm.setSubPosition1(this.getSubPosition1()); + alarm.setPosition2(this.getPosition2()); + alarm.setSubPosition2(this.getSubPosition2()); + alarm.setRegion(this.getRegion()); + alarm.setSite(this.getSite()); + + alarm.setSeverity(this.getSeverity()); + alarm.setAlarmType(this.getAlarmType()); + alarm.setSystemType(this.getSystemType()); + alarm.setSpecificProblem(this.getSpecificProblem()); + alarm.setAdditionalText(this.getAdditionalText()); + alarm.setProbableCause(this.getProbableCause()); + + alarm.setRaisedTime(this.getRaisedTime()); + alarm.setRaisedServerTime(this.getRaisedServerTime()); + alarm.setClearedTime(this.getClearedTime()); + + return alarm; + } + + @Override + public String getObjectId() { + return String.valueOf(id); + } + + public void addLinkIds(int linkId) { + linkIds.add(linkId); + } + + + public boolean containsPriority(String ruleId) { + if (priorityMap.keySet().contains(ruleId)) { + return true; + } + return false; + } + + public int getPriority(String ruleId) { + Integer priority = this.priorityMap.get(ruleId); + if (priority == null) { + priority = 0; + } + return priority; + } + + public int getRootAlarmType(String ruleId) { + Integer rootAlarmType = this.rootAlarmTypeMap.get(ruleId); + if (rootAlarmType == null) { + rootAlarmType = -1; + } + return rootAlarmType; + } + +} diff --git a/holmes-actions/src/main/java/org/openo/holmes/common/api/stat/AplusData.java b/holmes-actions/src/main/java/org/openo/holmes/common/api/stat/AplusData.java new file mode 100644 index 0000000..ce95a8d --- /dev/null +++ b/holmes-actions/src/main/java/org/openo/holmes/common/api/stat/AplusData.java @@ -0,0 +1,43 @@ +/** + * Copyright 2017 ZTE Corporation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.openo.holmes.common.api.stat; + +import java.io.Serializable; + +public interface AplusData extends Serializable { + + /** + * The data to be analyzed with aging characteristics - 0 + */ + byte APLUS_EVENT = 0; + + /** + * The data to be analyzed without aging characteristics - 1 + */ + byte APLUS_FACT = 1; + + + /** + * @see #APLUS_EVENT + * @see #APLUS_FACT + */ + byte getDataType(); + + /** + * @return String + */ + String getObjectId(); +} diff --git a/holmes-actions/src/main/java/org/openo/holmes/common/api/stat/AplusResult.java b/holmes-actions/src/main/java/org/openo/holmes/common/api/stat/AplusResult.java new file mode 100644 index 0000000..53c6729 --- /dev/null +++ b/holmes-actions/src/main/java/org/openo/holmes/common/api/stat/AplusResult.java @@ -0,0 +1,66 @@ +/** + * Copyright 2017 ZTE Corporation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.openo.holmes.common.api.stat; + +import java.io.Serializable; + +public interface AplusResult extends Serializable { + + /** + * Derived new alarm type - 0 + */ + byte APLUS_RAISED = 0; + + /** + * Correlation alarm, root-child alarm - 1 + */ + byte APLUS_CORRELATION = 1; + + /** + * cleared + */ + byte APLUS_CLEAR = 2; + + + int getId(); + + void setId(int id); + + String getRuleInfo(); + + void setRuleInfo(String ruleInfo); + + String getRuleType(); + + void setRuleType(String ruleType); + + void setRuleId(String ruleId); + + String getRuleId(); + + long getCreateTime(); + + void setCreateTime(long createTime); + + byte getResultType(); + + void setResultType(byte resultType); + + Alarm[] getAffectedAlarms(); + + void setAffectedAlarms(Alarm[] affectedAlarms); + +} diff --git a/holmes-actions/src/main/java/org/openo/holmes/common/constant/AlarmConst.java b/holmes-actions/src/main/java/org/openo/holmes/common/constant/AlarmConst.java new file mode 100644 index 0000000..b0d0b48 --- /dev/null +++ b/holmes-actions/src/main/java/org/openo/holmes/common/constant/AlarmConst.java @@ -0,0 +1,117 @@ +/** + * Copyright 2017 ZTE Corporation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.openo.holmes.common.constant; + +public interface AlarmConst { + + public static final String MQ_QUEUE_NAME_EMF_UP = "queue://zenap/fm/emf_up"; + + public static final String MQ_TOPIC_NAME_EMF_DOWN = "topic://zenap/fm/emf_down"; + + public static final String MQ_TOPIC_NAME_NORTH_UP = "topic://zenap/fm/north_up"; + + public static final String MQ_TOPIC_NAME_ALARM_RULE = "topic://zenap/fm/alarm_rule"; + + public static final String INTERNAL_MQ_QUEUE_NAME_HISTORY_ALARM_2_DB = "queue://zenap/fm/historyalarm2DB"; + + public static final String MQ_SELECTOR_KEY = "nf"; + + public static final String MQ_EMF_DOWN_MSG_FILTER_KEY = "type"; + + public static final String MQ_EMF_UP_MSG_FILTER_KEY = "type"; + + public static final String INTERNAL_MQ_EMF_UP_ACKALARM_MSG_FILTER_VALUE = "ACK"; + + public static final String MQ_EMF_DOWN_CLEARALARM_MSG_FILTER_VALUE = "CLEAR"; + + public static final String MQ_EMF_UP_CLEARALARM_MSG_FILTER_VALUE = "CLEAR"; + + public static final String MQ_EMF_UP_CHANGEALARM_MSG_FILTER_VALUE = "CHANGE"; + + public static final String MQ_EMF_UP_RAISEALARM_MSG_FILTER_VALUE = "RAISE"; + + public static final String INTERNAL_MQ_CLEARALARM_2_DB_FILTER_VALUE = "CLEAR"; + + public static final String COMETD_MESSAGE_TOPIC = "cometd2Client"; + + public static final String COMETD_MESSAGE_CHANEL = "/broadcast_channel/alarm_cometd_chanel"; + + public static final String COMETD_NF_COUNTER_CHANEL = "/nf_counter_cometd_chanel"; + + public static final String COMETD_PROMPTING_RULE_CHANEL = "/prompting_rule_cometd_chanel"; + + public static final String COMETD_MASK_RULE_MESSAGE_FILTER_KEY = "mask_rule"; + + public static final String COMETD_CLEAR_ALARM_MESSAGE_FILTER_KEY = "clear_alarm"; + + public static final String COMETD_ACK_ALARM_MESSAGE_FILTER_KEY = "ack_alarm"; + + public static final String COMETD_HISTORY_ALARM_ACK_STATE_MESSAGE_FILTER_KEY = "history_alarm_ack"; + + public static final String CACHE_ACTIVE_ALARM_KEY = "TAG_ACTIVE_ALARM"; + + public static final String CACHE_ALARM_CODE_KEY = "TAG_ALARM_CODE"; + + public static final String CACHE_ALARM_RESTYPE_AND_RESVERSION_KEY = "TAG_ALARM_RESTYPE_AND_RESVERSION"; + + public static final String CACHE_ALARM_REASON_KEY = "TAG_ALARM_REASON"; + + public static final String CACHE_ALARM_MAIN_KEY = "TAG_ALARM_MAIN"; + + public static final short STATUS_ENABLE = 0; + + public static final short STATUS_DISABLE = 1; + + public static final short STATUS_DELETED = 2; + + public static final short UNDEFINE_LEVEL = 0; + + public static final short CRITICA_LEVEL = 1; + + public static final short MAJOR_LEVEL = 2; + + public static final short MINOR_LEVEL = 3; + + public static final short WARNING_LEVEL = 4; + + public static final String I18N_EN = "en"; + + public static final String I18N_ZH = "zh"; + + public static final String ZH_CN = "zh_CN"; + + public static final String EN_US = "en_US"; + + public static final String EXECUTE_TIMER = "0 0 0 */1 * ? "; + + public static final String COMMON_EM_RESTYPE = "common_em"; + + public static final String EM_LOCATION = "em"; + + public static final String BASE_MOC = "em"; + + public static final String SYSTEM_ID = "SystemId"; + + public static final String ADMIN = "admin"; + + public static final long UNDEFINE_ALARM_CODE = -1; + + // for rule code + public static final long FORWARD_FAILED_ALARM_CODE = 1028L; + + public static long ACTIVE_PERSISTING_RULE_CODE = 1017L; + public static long UNACKNOWLEDGED_PERSISTING_RULE_CODE = 1018L; +} diff --git a/holmes-actions/src/main/java/org/openo/holmes/common/constant/MicroServiceConst.java b/holmes-actions/src/main/java/org/openo/holmes/common/constant/MicroServiceConst.java new file mode 100644 index 0000000..c0f5d5e --- /dev/null +++ b/holmes-actions/src/main/java/org/openo/holmes/common/constant/MicroServiceConst.java @@ -0,0 +1,28 @@ +/** + * Copyright 2017 ZTE Corporation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.openo.holmes.common.constant; + +public interface MicroServiceConst { + + public static final String CORRELATION_ENGINE = "correlation-engine"; + + public static final String VERSION = "v1"; + + public static final String ENGINE_PATH = "/api/correlation-engine/v1/rule"; + + public static final String CORRELATION_ENGINE_SERVICE_NAME = CORRELATION_ENGINE; + +} diff --git a/holmes-actions/src/main/java/org/openo/holmes/common/db/AlarmCorrelationQueryDao.java b/holmes-actions/src/main/java/org/openo/holmes/common/db/AlarmCorrelationQueryDao.java new file mode 100644 index 0000000..3e8bfc8 --- /dev/null +++ b/holmes-actions/src/main/java/org/openo/holmes/common/db/AlarmCorrelationQueryDao.java @@ -0,0 +1,57 @@ +/** + * Copyright 2017 ZTE Corporation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.openo.holmes.common.db; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import javax.inject.Inject; + +import org.jvnet.hk2.annotations.Service; +import org.openo.holmes.common.api.entity.AlarmsCorrelation; +import org.skife.jdbi.v2.Query; + +import org.openo.holmes.common.db.mapper.AlarmsCorrelationMapper; +import org.openo.holmes.common.utils.DbDaoUtil; + +import lombok.extern.slf4j.Slf4j; + +@Service +@Slf4j +public class AlarmCorrelationQueryDao { + + @Inject + private DbDaoUtil dbDaoUtil; + + @Inject + private AlarmsCorrelationMapper mapper; + + private final static String SELECT_TABLE_SQL = "SELECT * FROM APLUS_CORRELATION "; + + public List queryByFilter(String where) { + List alarmsCorrelations = new ArrayList(); + StringBuilder querySql = new StringBuilder(SELECT_TABLE_SQL).append(where); + log.info("Query alarm correlation table! Sql:[" + querySql + "]."); + Query> query = dbDaoUtil.getHandle().createQuery(querySql.toString()); + List> dbDataMaps = query.list(); + for (Map map : dbDataMaps) { + alarmsCorrelations.add(mapper.getAlarmCorrelationByMap(map)); + } + log.info("Success to query alarm correlation table! total count:[" + dbDataMaps.size() + "]."); + return alarmsCorrelations; + } +} diff --git a/holmes-actions/src/main/java/org/openo/holmes/common/db/AlarmsCorrelationDao.java b/holmes-actions/src/main/java/org/openo/holmes/common/db/AlarmsCorrelationDao.java new file mode 100644 index 0000000..43c8bf2 --- /dev/null +++ b/holmes-actions/src/main/java/org/openo/holmes/common/db/AlarmsCorrelationDao.java @@ -0,0 +1,36 @@ +/** + * Copyright 2017 ZTE Corporation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.openo.holmes.common.db; + +import java.util.List; + +import org.openo.holmes.common.api.entity.AlarmsCorrelation; +import org.skife.jdbi.v2.sqlobject.BindBean; +import org.skife.jdbi.v2.sqlobject.SqlQuery; +import org.skife.jdbi.v2.sqlobject.SqlUpdate; +import org.skife.jdbi.v2.sqlobject.customizers.RegisterMapper; + +import org.openo.holmes.common.db.mapper.AlarmsCorrelationMapper; + +@RegisterMapper(AlarmsCorrelationMapper.class) +public interface AlarmsCorrelationDao { + + @SqlUpdate("INSERT INTO APLUS_CORRELATION (ruleId,ruleInfo,resultType,createTime,parentAlarmId,childAlarmId,reserve1,reserve2,reserve3) values(:ruleId,:ruleInfo,:resultType,:createTime,:parentAlarmId,:childAlarmId,:reserve1,:reserve2,:reserve3)") + public abstract void save(@BindBean AlarmsCorrelation aplusCorrelation); + + @SqlQuery("SELECT * FROM APLUS_CORRELATION") + public abstract List queryAll(); +} diff --git a/holmes-actions/src/main/java/org/openo/holmes/common/db/mapper/AlarmsCorrelationMapper.java b/holmes-actions/src/main/java/org/openo/holmes/common/db/mapper/AlarmsCorrelationMapper.java new file mode 100644 index 0000000..2fc2968 --- /dev/null +++ b/holmes-actions/src/main/java/org/openo/holmes/common/db/mapper/AlarmsCorrelationMapper.java @@ -0,0 +1,86 @@ +/** + * Copyright 2017 ZTE Corporation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.openo.holmes.common.db.mapper; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.Date; +import java.util.Map; + +import org.jvnet.hk2.annotations.Service; +import org.openo.holmes.common.api.entity.AlarmsCorrelation; +import org.skife.jdbi.v2.StatementContext; +import org.skife.jdbi.v2.tweak.ResultSetMapper; + +@Service +public class AlarmsCorrelationMapper implements ResultSetMapper { + + private final static String RULE_ID = "ruleId"; + private final static String RULE_INFO = "ruleInfo"; + private final static String RESULT_TYPE = "resultType"; + private final static String CREATE_TIME = "createTime"; + private final static String PARENT_ALARM_ID = "parentAlarmId"; + private final static String CHILD_ALARM_ID = "childAlarmId"; + private final static String RESERVE1 = "reserve1"; + private final static String RESERVE2 = "reserve2"; + private final static String RESERVE3 = "reserve3"; + + @Override + public AlarmsCorrelation map(int i, ResultSet resultSet, StatementContext statementContext) + throws SQLException { + AlarmsCorrelation aplusCorrelation = new AlarmsCorrelation(); + aplusCorrelation.setRuleId(resultSet.getString(RULE_ID)); + aplusCorrelation.setRuleInfo(resultSet.getString(RULE_INFO)); + aplusCorrelation.setResultType(resultSet.getByte(RESULT_TYPE)); + aplusCorrelation.setCreateTime(resultSet.getDate(CREATE_TIME)); + aplusCorrelation.setParentAlarmId(resultSet.getLong(PARENT_ALARM_ID)); + aplusCorrelation.setChildAlarmId(resultSet.getLong(CHILD_ALARM_ID)); + aplusCorrelation.setReserve1(resultSet.getLong(RESERVE1)); + aplusCorrelation.setReserve2(resultSet.getLong(RESERVE2)); + aplusCorrelation.setReserve3(resultSet.getLong(RESERVE3)); + return aplusCorrelation; + } + + public AlarmsCorrelation getAlarmCorrelationByMap(Map map) { + AlarmsCorrelation aplusCorrelation = new AlarmsCorrelation(); + aplusCorrelation.setRuleId(getStringValue4Map(map, RULE_ID)); + aplusCorrelation.setRuleInfo(getStringValue4Map(map, RULE_INFO)); + aplusCorrelation.setResultType(getByteValue4Map(map, RESULT_TYPE, -1)); + aplusCorrelation.setCreateTime((Date) map.get(CREATE_TIME)); + aplusCorrelation.setParentAlarmId(getLongValue4Map(map, PARENT_ALARM_ID, -1)); + aplusCorrelation.setChildAlarmId(getLongValue4Map(map, CHILD_ALARM_ID, -1)); + aplusCorrelation.setReserve1(getLongValue4Map(map, RESERVE1, -1)); + aplusCorrelation.setReserve2(getLongValue4Map(map, RESERVE2, -1)); + aplusCorrelation.setReserve3(getLongValue4Map(map, RESERVE3, -1)); + return aplusCorrelation; + } + + private String getStringValue4Map(Map map, String key) { + Object value = map.get(key); + return value == null ? "" : String.valueOf(value); + } + + private long getLongValue4Map(Map map, String key, long defaultValue) { + Object value = map.get(key); + return value == null ? defaultValue : Long.valueOf(String.valueOf(value)); + } + + private byte getByteValue4Map(Map map, String key, int defaultValue) { + Object value = map.get(key); + return value == null ? Byte.valueOf(String.valueOf(defaultValue)) + : Byte.valueOf(String.valueOf(value)); + } +} diff --git a/holmes-actions/src/main/java/org/openo/holmes/common/exception/CallException.java b/holmes-actions/src/main/java/org/openo/holmes/common/exception/CallException.java new file mode 100644 index 0000000..fe32b26 --- /dev/null +++ b/holmes-actions/src/main/java/org/openo/holmes/common/exception/CallException.java @@ -0,0 +1,26 @@ +/** + * Copyright 2017 ZTE Corporation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.openo.holmes.common.exception; + +public class CallException extends Exception { + public CallException(String msg, Exception e) { + super(msg, e); + } + + public CallException(String msg) { + super(msg); + } +} \ No newline at end of file diff --git a/holmes-actions/src/main/java/org/openo/holmes/common/exception/DataFormatException.java b/holmes-actions/src/main/java/org/openo/holmes/common/exception/DataFormatException.java new file mode 100644 index 0000000..7fcc3b2 --- /dev/null +++ b/holmes-actions/src/main/java/org/openo/holmes/common/exception/DataFormatException.java @@ -0,0 +1,26 @@ +/** + * Copyright 2017 ZTE Corporation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.openo.holmes.common.exception; + +public class DataFormatException extends Exception { + public DataFormatException(String msg, Exception e ) { + super( msg, e ); + } + + public DataFormatException(String msg ) { + super( msg ); + } +} diff --git a/holmes-actions/src/main/java/org/openo/holmes/common/exception/DbException.java b/holmes-actions/src/main/java/org/openo/holmes/common/exception/DbException.java new file mode 100644 index 0000000..d616481 --- /dev/null +++ b/holmes-actions/src/main/java/org/openo/holmes/common/exception/DbException.java @@ -0,0 +1,28 @@ +/** + * Copyright 2017 ZTE Corporation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.openo.holmes.common.exception; + +public class DbException extends Exception { + private static final long serialVersionUID = 6218393740013925907L; + + public DbException( String msg, Exception e ) { + super( msg, e ); + } + + public DbException( String msg ) { + super( msg ); + } +} diff --git a/holmes-actions/src/main/java/org/openo/holmes/common/exception/EngineException.java b/holmes-actions/src/main/java/org/openo/holmes/common/exception/EngineException.java new file mode 100644 index 0000000..d61901d --- /dev/null +++ b/holmes-actions/src/main/java/org/openo/holmes/common/exception/EngineException.java @@ -0,0 +1,32 @@ +/** + * Copyright 2017 ZTE Corporation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.openo.holmes.common.exception; + +public class EngineException extends Exception{ + public EngineException () {} + + public EngineException(String msg) { + super(msg); + } + + public EngineException(String msg, Throwable cause){ + super(msg, cause); + } + + public EngineException(Throwable cause){ + super(cause); + } +} diff --git a/holmes-actions/src/main/java/org/openo/holmes/common/exception/RuleIllegalityException.java b/holmes-actions/src/main/java/org/openo/holmes/common/exception/RuleIllegalityException.java new file mode 100644 index 0000000..5b1d3bd --- /dev/null +++ b/holmes-actions/src/main/java/org/openo/holmes/common/exception/RuleIllegalityException.java @@ -0,0 +1,32 @@ +/** + * Copyright 2017 ZTE Corporation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.openo.holmes.common.exception; + +public class RuleIllegalityException extends Exception{ + public RuleIllegalityException() {} + + public RuleIllegalityException(String msg) { + super(msg); + } + + public RuleIllegalityException(String msg, Throwable cause){ + super(msg, cause); + } + + public RuleIllegalityException(Throwable cause){ + super(cause); + } +} diff --git a/holmes-actions/src/main/java/org/openo/holmes/common/i18n/correlation-i18n-en-US.json b/holmes-actions/src/main/java/org/openo/holmes/common/i18n/correlation-i18n-en-US.json new file mode 100644 index 0000000..9aa6357 --- /dev/null +++ b/holmes-actions/src/main/java/org/openo/holmes/common/i18n/correlation-i18n-en-US.json @@ -0,0 +1,29 @@ +{ + "ENGINE_CONTENT_ILLEGALITY": "The rule content have error:{0}", + "ENGINE_DEPLOY_RULE_FAILED": "Deploy rule failed", + "ENGINE_DELETE_RULE_NULL": "The rule do not exist :{0}", + "ENGINE_DELETE_RULE_FAILED": "The rule remove failed :{0}", + "ENGINE_INSERT_RULE_CACHE_FAILED": "insert rule failed in cache", + "ENGINE_DELETE_RULE_FAILED_FROM_CACHE": "delete rule failed in cache", + "ENGINE_CONTAINS_PACKAGE": "Is included in the package name, please amend", + "ENGINE_QUERY_CACHE_FAILED": "Failed query cache", + "EXCEPTION_DB_RULE_NOT_EXIST_ERROR": "This rule does not exist in the database.", + "EXCEPTION_DB_RULE_SAVE_ERROR": "Error saving rule to database", + "EXCEPTION_DB_RULE_GET_ERROR": "Error when get rule from database", + "EXCEPTION_REQUEST_IS_EMPTY": "The request object is empty", + "RULE_MANAGEMENT_CALL_DELETE_RULE_REST_FAILED": "Delete rules from engine call interface failure ", + "RULE_MANAGEMENT_CALL_DEPLOY_RULE_REST_FAILED": "From the rules engine calls the deployment of interface failure", + "RULE_MANAGEMENT__CALL_CHECK_RULE_REST_FAILED": "From the rules engine calls the check of interface failure", + "RULE_MANAGEMENT_CREATE_QUERY_SQL_FAILED": "Create query exception", + "RULE_MANAGEMENT_QUERY_RULE_FAILED": "Query rule failed", + "RULE_MANAGEMENT_CREATE_RULE_FAILED": "Failed to create rule", + "RULE_MANAGEMENT_DELETE_RULE_FAILED": "Delete rule failed", + "RULE_MANAGEMENT_UPDATE_RULE_FAILED": "Update rule failed", + "RULE_MANAGEMENT_REQUEST_OBJECT_IS_EMPTY": "Request object is empty", + "RULE_MANAGEMENT_RULE_NOT_EXIST_DATABASE": "Rule does not exist", + "RULE_MANAGEMENT_UNKNOWN_EXCEPTION": "Unknown exception", + "RULE_MANAGEMENT_REPEAT_RULE_NAME": "Rule name repetition", + "RULE_MANAGEMENT_RULE_NAME_IS_EMPTY": "Rule name is empty", + "RULE_MANAGEMENT_DATA_FORMAT_ERROR": "Data format error", + "RULE_MANAGEMENT_PARAMETER_ENABLED_ERROR": "Parameter enabled can only be 0 (not enabled) and 1 (enabled)" +} diff --git a/holmes-actions/src/main/java/org/openo/holmes/common/i18n/correlation-i18n-zh-CN.json b/holmes-actions/src/main/java/org/openo/holmes/common/i18n/correlation-i18n-zh-CN.json new file mode 100644 index 0000000..9ca28fe --- /dev/null +++ b/holmes-actions/src/main/java/org/openo/holmes/common/i18n/correlation-i18n-zh-CN.json @@ -0,0 +1,25 @@ +{ + "ENGINE_CONTENT_ILLEGALITY": "规则内容有误:{0}", + "ENGINE_DEPLOY_RULE_FAILED": "部署规则失败", + "ENGINE_DELETE_RULE_NULL": "引擎不包含这个规则:{0}", + "ENGINE_DELETE_RULE_FAILED": "删除规则失败{0}", + "ENGINE_INSERT_RULE_CACHE_FAILED": "插入数据到缓存失败", + "ENGINE_DELETE_RULE_FAILED_FROM_CACHE": "从缓存删除数据失败", + "ENGINE_CONTAINS_PACKAGE": "package 名字已包含,请修改", + "ENGINE_QUERY_CACHE_FAILED":"查询缓存失败", + "RULE_MANAGEMENT_CALL_DELETE_RULE_REST_FAILED": "从引擎调用删除规则接口失败", + "RULE_MANAGEMENT_CALL_DEPLOY_RULE_REST_FAILED": "从引擎调用部署规则接口失败", + "RULE_MANAGEMENT__CALL_CHECK_RULE_REST_FAILED": "从引擎调用校验规则接口失败", + "RULE_MANAGEMENT_CREATE_QUERY_SQL_FAILED": "创建查询语句异常", + "RULE_MANAGEMENT_QUERY_RULE_FAILED": "查询规则失败", + "RULE_MANAGEMENT_CREATE_RULE_FAILED": "创建规则失败", + "RULE_MANAGEMENT_DELETE_RULE_FAILED": "删除规则失败", + "RULE_MANAGEMENT_UPDATE_RULE_FAILED": "更新规则失败", + "RULE_MANAGEMENT_REQUEST_OBJECT_IS_EMPTY":"请求对象为空", + "RULE_MANAGEMENT_RULE_NOT_EXIST_DATABASE": "规则不存在", + "RULE_MANAGEMENT_UNKNOWN_EXCEPTION": "未知异常", + "RULE_MANAGEMENT_REPEAT_RULE_NAME" : "规则名字重复", + "RULE_MANAGEMENT_RULE_NAME_IS_EMPTY" : "规则名字为空", + "RULE_MANAGEMENT_DATA_FORMAT_ERROR": "数据格式异常", + "RULE_MANAGEMENT_PARAMETER_ENABLED_ERROR" : "参数enabled只能为0(未启用)和1(启用)" +} diff --git a/holmes-actions/src/main/java/org/openo/holmes/common/i18n/correlation-operationcode-i18n-en-US.json b/holmes-actions/src/main/java/org/openo/holmes/common/i18n/correlation-operationcode-i18n-en-US.json new file mode 100644 index 0000000..b7d4853 --- /dev/null +++ b/holmes-actions/src/main/java/org/openo/holmes/common/i18n/correlation-operationcode-i18n-en-US.json @@ -0,0 +1,87 @@ +{ + "ADD_QUERY_COND":"Add active alarm query condition", + "MODIFY_QUERY_COND":"Modify active alarm query condition", + "QUERY_ALL_QUERY_COND":"Query all active alarm query conditions", + "DELETE_QUERY_COND":"Delete active alarm query condition", + "ADD_ALARM_ACK_RULE":"Add active alarm acknowledge rule", + "MODIFY_ALARM_ACK_RULE":"Modify active alarm acknowledge rule", + "QUERY_ALARM_ACK_RULE":"Query active alarm acknowledge rule", + "ADD_FILTER_RULE":"Add alarm filter rule", + "MODIFY_FILTER_RULE":"Modify alarm filter rule", + "QUERY_FILTER_RULE":"Query alarm filter rule", + "ADD_MASK_RULE":"Add mask rule", + "MODIFY_MASK_RULE":"Modify mask rule", + "ADD_CLEAR_RULE":"Add clear rule", + "MODIFY_CLEAR_RULE":"Modify clear rule", + "QUERY_CLEAR_RULE":"Query clear rule", + "ADD_COUNT_RULE":"Add count rule", + "MODIFY_COUNT_RULE":"Modify count rule", + "QUERY_COUNT_RULE":"Query count rule", + "ADD_DELAY_TIME_RULE":"Add delay time rule", + "MODIFY_DELAY_TIME_RULE":"Modify delay time rule", + "QUERY_DELAY_TIME_RULE":"Query delay time rule", + "ADD_FORWARD_RULE":"Add forward rule", + "MODIFY_FORWARD_RULE":"Modify forward rule", + "QUERY_FORWARD_RULE":"Query forward rule", + "ADD_INTERMITTENT_ALARM_RULE":"Add intermittent alarm rule", + "MODIFY_INTERMITTENT_ALARM_RULE":"Modify intermittent alarm rule", + "ADD_MERGE_RULE":"Add merge rule", + "MODIFY_MERGE_RULE":"Modify merge rule", + "QUERY_MERGE_RULE":"Query merge rule", + "ADD_NOTIFICATION_FILTER_RULE":"Add notification filter rule", + "MODIFY_NOTIFICATION_FILTER_RULE":"Modify notification filter rule", + "QUERY_NOTIFICATION_FILTER_RULE":"Query notification filter rule", + "ADD_PERSISTING_RULE":"Add persisting rule", + "MODIFY_PERSISTING_RULE":"Modify persisting rule", + "QUERY_PERSISTING_RULE":"Query persisting rule", + "ADD_PROMPTING_RULE":"Add prompting rule", + "MODIFY_PROMPTING_RULE":"Modify persisting rule", + "QUERY_PROMPTING_RULE":"Query persisting rule", + "SUSPEND_RULE":"Suspend rule", + "SUSPEND_RULE_FAIL":"Suspend rule failed", + "ACTIVATE_RULE":"Activate rule", + "ACTIVATE_RULE_FAIL":"activate rule failed", + "DELETED_RULE":"Deleted rule", + "DELETE_RULE_FAIL":"delete rule failed", + "QUERY_RULE_TYPE":"Query rule type", + "QUERY_RULE_TYPE_FAIL":"Query rule type failed", + "QUERY_RULE_BY_TYPE":"Query all rule by rule types", + "QUERY_TIMING_REPORT_RULE":"Query timing report rule", + "ADD_TIMING_REPORT_RULE":"Add timing report rule", + "MODIFY_TIMING_REPORT_RULE":"Modify timing report rule", + "QUERY_TIMING_REPORT_TASK_LOG":"Query timing report task execute log", + "DELETED_TIMING_REPORT_RULE":"Deleted timing report rule", + "DELETED_TIMING_REPORT_RULE_FAIL":"Deleted timing report rule failed", + "ACTIVATE_TIMING_REPORT_RULE":"Activate timing report rule", + "ACTIVATE_TIMING_REPORT_RULE_FAIL":"Activate timing report rule failed", + "SUSPEND_TIMING_REPORT_RULE":"Suspend timing report rule", + "SUSPEND_TIMING_REPORT_RULE_FAIL":"Suspend timing report rule failed", + "QUERY_HISTORY_TIMING_REPORT_RULE":"Query history timing report rule", + "ADD_HISTORY_TIMING_REPORT_RULE":"Add history timing report rule", + "MODIFY_HISTORY_TIMING_REPORT_RULE":"Modify history timing report rule", + "DELETED_HISTORY_TIMING_REPORT_RULE":"Deleted history timing report rule", + "DELETED_HISTORY_TIMING_REPORT_RULE_FAIL":"Deleted history timing report rule failed", + "ACTIVATE_HISTORY_TIMING_REPORT_RULE":"Activate history timing report rule", + "ACTIVATE_HISTORY_TIMING_REPORT_RULE_FAIL":"Activate history timing report rule failed", + "SUSPEND_HISTORY_TIMING_REPORT_RULE":"Suspend history timing report rule", + "SUSPEND_HISTORY_TIMING_REPORT_RULE_FAIL":"Suspend history timing report rule failed", + "QUERY_HISTORY_TIMING_REPORT_TASK_LOG":"Query history timing report task execution log", + "ADD_HISTORY_ALARM_QUERY_COND":"Add history alarm query condition", + "MODIFY_HISTORY_ALARM_QUERY_COND":"Modify history alarm query condition", + "QUERY_HISTORY_ALARM_QUERY_COND":"Query history alarm query condition", + "DELETED_HISTORY_ALARM_QUERY_COND":"Deleted history alarm query condition", + "ADD_NOTIFICATION_QUERY_COND":"Add notification query condition", + "MODIFY_NOTIFICATION_QUERY_COND":"Modify notification query condition", + "QUERY_NOTIFICATION_QUERY_COND":"Query notification query condition", + "DELETED_NOTIFICATION_QUERY_COND":"Deleted notification query condition", + "QUERY_BASIC_STATISTIC_TEMPLATE":"Query basic statistic template", + "ADD_BASIC_STATISTIC_TEMPLATE":"Add basic statistic template", + "MODIFY_BASIC_STATISTIC_TEMPLATE":"Modify basic statistic template", + "DELETED_BASIC_STATISTIC_TEMPLATE":"Deleted basic statistic template", + "MODIFY_BASIC_STATISTIC_TEMPLATE_AS_DEFAULT":"Modify basic statistic template as default template", + "QUERY_BUSY_TIME_STATISTIC_TEMPLATE":"Query busy time statistic template", + "ADD_BUSY_TIME_STATISTIC_TEMPLATE":"Add busy time statistic template", + "MODIFY_BUSY_TIME_STATISTIC_TEMPLATE":"Modify busy time statistic template", + "DELETED_BUSY_TIME_STATISTIC_TEMPLATE":"Deleted busy time statistic template", + "MODIFY_BUSY_TIME_STATISTIC_TEMPLATE_AS_DEFAULT":"Modify busy time statistic template as default template" +} diff --git a/holmes-actions/src/main/java/org/openo/holmes/common/i18n/correlation-operationcode-i18n-zh-CN.json b/holmes-actions/src/main/java/org/openo/holmes/common/i18n/correlation-operationcode-i18n-zh-CN.json new file mode 100644 index 0000000..0509c3b --- /dev/null +++ b/holmes-actions/src/main/java/org/openo/holmes/common/i18n/correlation-operationcode-i18n-zh-CN.json @@ -0,0 +1,87 @@ +{ + "ADD_QUERY_COND":"添加当前告警查询条件", + "MODIFY_QUERY_COND":"修改当前告警查询条件", + "QUERY_ALL_QUERY_COND":"查询所有当前告警查询条件", + "DELETE_QUERY_COND":"删除当前告警查询条件", + "ADD_ALARM_ACK_RULE":"添加当前告警确认规则", + "MODIFY_ALARM_ACK_RULE":"修改当前告警确认规则", + "QUERY_ALARM_ACK_RULE":"查询当前告警确认规则", + "ADD_FILTER_RULE":"添加告警过滤规则", + "MODIFY_FILTER_RULE":"修改告警过滤规则", + "QUERY_FILTER_RULE":"查询告警过滤规则", + "ADD_MASK_RULE":"添加屏蔽规则", + "MODIFY_MASK_RULE":"修改屏蔽规则", + "ADD_CLEAR_RULE":"添加清除规则", + "MODIFY_CLEAR_RULE":"修改清除规则", + "QUERY_CLEAR_RULE":"查询清除规则", + "ADD_COUNT_RULE":"添加计数规则", + "MODIFY_COUNT_RULE":"修改计数规则", + "QUERY_COUNT_RULE":"查询计数规则", + "ADD_DELAY_TIME_RULE":"添加延时规则", + "MODIFY_DELAY_TIME_RULE":"修改延时规则", + "QUERY_DELAY_TIME_RULE":"查询延时规则", + "ADD_FORWARD_RULE":"添加前转规则", + "MODIFY_FORWARD_RULE":"修改前转规则", + "QUERY_FORWARD_RULE":"查询前转规则", + "ADD_INTERMITTENT_ALARM_RULE":"添加闪断规则", + "MODIFY_INTERMITTENT_ALARM_RULE":"修改闪断规则", + "ADD_MERGE_RULE":"添加归并规则", + "MODIFY_MERGE_RULE":"修改归并规则", + "QUERY_MERGE_RULE":"查询归并规则", + "ADD_NOTIFICATION_FILTER_RULE":"添加通知过滤规则", + "MODIFY_NOTIFICATION_FILTER_RULE":"修改通知过滤规则", + "QUERY_NOTIFICATION_FILTER_RULE":"查询通知过滤规则", + "ADD_PERSISTING_RULE":"添加计时规则", + "MODIFY_PERSISTING_RULE":"修改计时规则", + "QUERY_PERSISTING_RULE":"查询计时规则", + "ADD_PROMPTING_RULE":"添加提示规则", + "MODIFY_PROMPTING_RULE":"修改提示规则", + "QUERY_PROMPTING_RULE":"查询提示规则", + "SUSPEND_RULE":"暂停规则", + "SUSPEND_RULE_FAIL":"暂停规则失败", + "ACTIVATE_RULE":"激活规则", + "ACTIVATE_RULE_FAIL":"激活规则失败", + "DELETED_RULE":"删除规则", + "DELETE_RULE_FAIL":"删除规则失败", + "QUERY_RULE_TYPE":"查询规则类型", + "QUERY_RULE_TYPE_FAIL":"查询规则类型失败", + "QUERY_RULE_BY_TYPE":"通过规则类型查询所有规则", + "QUERY_TIMING_REPORT_RULE":"查询定时输出规则", + "ADD_TIMING_REPORT_RULE":"添加定时输出规则", + "MODIFY_TIMING_REPORT_RULE":"修改定时输出规则", + "QUERY_TIMING_REPORT_TASK_LOG":"查询定时输出任务的执行日志", + "DELETED_TIMING_REPORT_RULE":"删除定时输出规则", + "DELETED_TIMING_REPORT_RULE_FAIL":"删除定时输出规则失败", + "ACTIVATE_TIMING_REPORT_RULE":"激活定时输出规则", + "ACTIVATE_TIMING_REPORT_RULE_FAIL":"激活定时输出规则失败", + "SUSPEND_TIMING_REPORT_RULE":"暂停定时输出规则", + "SUSPEND_TIMING_REPORT_RULE_FAIL":"暂停定时输出规则失败", + "QUERY_HISTORY_TIMING_REPORT_RULE":"查询历史定时输出规则", + "ADD_HISTORY_TIMING_REPORT_RULE":"添加历史定时输出规则", + "MODIFY_HISTORY_TIMING_REPORT_RULE":"修改历史定时输出规则", + "DELETED_HISTORY_TIMING_REPORT_RULE":"删除历史定时输出规则", + "DELETED_HISTORY_TIMING_REPORT_RULE_FAIL":"删除历史定时输出规则失败", + "ACTIVATE_HISTORY_TIMING_REPORT_RULE":"激活历史定时输出规则", + "ACTIVATE_HISTORY_TIMING_REPORT_RULE_FAIL":"激活历史定时输出规则失败", + "SUSPEND_HISTORY_TIMING_REPORT_RULE":"暂停历史定时输出规则", + "SUSPEND_HISTORY_TIMING_REPORT_RULE_FAIL":"暂停历史定时输出规则失败", + "QUERY_HISTORY_TIMING_REPORT_TASK_LOG":"查询历史定时输出任务的执行日志", + "ADD_HISTORY_ALARM_QUERY_COND":"添加历史告警查询条件", + "MODIFY_HISTORY_ALARM_QUERY_COND":"修改历史告警查询条件", + "QUERY_HISTORY_ALARM_QUERY_COND":"查询历史告警查询条件", + "DELETED_HISTORY_ALARM_QUERY_COND":"删除历史告警查询条件", + "ADD_NOTIFICATION_QUERY_COND":"添加通知查询条件", + "MODIFY_NOTIFICATION_QUERY_COND":"修改通知查询条件", + "QUERY_NOTIFICATION_QUERY_COND":"查询通知查询条件", + "DELETED_NOTIFICATION_QUERY_COND":"删除通知查询条件", + "QUERY_BASIC_STATISTIC_TEMPLATE":"查询基础统计模板", + "ADD_BASIC_STATISTIC_TEMPLATE":"添加基础统计模板", + "MODIFY_BASIC_STATISTIC_TEMPLATE":"修改基础统计模板", + "DELETED_BASIC_STATISTIC_TEMPLATE":"删除基础统计模板", + "MODIFY_BASIC_STATISTIC_TEMPLATE_AS_DEFAULT":"修改基础统计模板为默认模板", + "QUERY_BUSY_TIME_STATISTIC_TEMPLATE":"查询忙时统计模板", + "ADD_BUSY_TIME_STATISTIC_TEMPLATE":"添加忙时统计模板", + "MODIFY_BUSY_TIME_STATISTIC_TEMPLATE":"修改忙时统计模板", + "DELETED_BUSY_TIME_STATISTIC_TEMPLATE":"删除忙时统计模板", + "MODIFY_BUSY_TIME_STATISTIC_TEMPLATE_AS_DEFAULT":"修改忙时统计模板为默认模板" +} diff --git a/holmes-actions/src/main/java/org/openo/holmes/common/utils/DateForJsonSerializer.java b/holmes-actions/src/main/java/org/openo/holmes/common/utils/DateForJsonSerializer.java new file mode 100644 index 0000000..fe36d74 --- /dev/null +++ b/holmes-actions/src/main/java/org/openo/holmes/common/utils/DateForJsonSerializer.java @@ -0,0 +1,37 @@ +/** + * Copyright 2017 ZTE Corporation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.openo.holmes.common.utils; + +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonSerializer; +import com.fasterxml.jackson.databind.SerializerProvider; + +import java.io.IOException; +import java.text.SimpleDateFormat; +import java.util.Date; + +public class DateForJsonSerializer extends JsonSerializer < Date > { + @Override + public void serialize( Date date, JsonGenerator jsonGenerator, + SerializerProvider serializerProvider ) throws IOException, JsonProcessingException { + if ( date != null ) { + SimpleDateFormat formatter = new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ss.SSSXXX" ); + String formattedDate = formatter.format( date ); + jsonGenerator.writeString( formattedDate ); + } + } +} diff --git a/holmes-actions/src/main/java/org/openo/holmes/common/utils/DbDaoUtil.java b/holmes-actions/src/main/java/org/openo/holmes/common/utils/DbDaoUtil.java new file mode 100644 index 0000000..fcd90aa --- /dev/null +++ b/holmes-actions/src/main/java/org/openo/holmes/common/utils/DbDaoUtil.java @@ -0,0 +1,93 @@ +/** + * Copyright 2017 ZTE Corporation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.openo.holmes.common.utils; + +import io.dropwizard.db.DataSourceFactory; +import io.dropwizard.jdbi.DBIFactory; +import io.dropwizard.setup.Environment; +import javax.inject.Inject; +import javax.inject.Singleton; +import lombok.extern.slf4j.Slf4j; +import org.glassfish.hk2.api.IterableProvider; +import org.jvnet.hk2.annotations.Service; +import org.skife.jdbi.v2.DBI; +import org.skife.jdbi.v2.Handle; + +@Singleton +@Service +@Slf4j +public class DbDaoUtil { + + private static DBI jdbi; + + @Inject + private static IterableProvider environmentProvider; + + @Inject + private static IterableProvider dataSourceFactoryProvider; + + static { + if (jdbi == null) { + synchronized (DbDaoUtil.class) { + if (jdbi == null) { + final DBIFactory factory = new DBIFactory(); + jdbi = factory + .build(environmentProvider.get(), dataSourceFactoryProvider.get(), "mysql"); + } + } + } + } + + public K getDao(Class clazz) { + try { + return jdbi.open(clazz); + } catch (Exception e) { + log.warn("get object instance of Dao error.", e); + } + return null; + } + + public Handle getHandle() { + try { + return jdbi.open(); + } catch (Exception e) { + log.warn("get object instance of Dao error.", e); + } + return null; + } + + public void close(Object obj) { + if (obj != null) { + try { + jdbi.close(obj); + } catch (Exception e) { + log.warn("close jdbi connection error.", e); + } + } + } + + public T getJdbiDaoByOnDemand(Class daoClazz) { + + return jdbi.onDemand(daoClazz); + + } + + public T getJdbiDaoByOpen(Class daoClazz) { + + return jdbi.open(daoClazz); + + } +} diff --git a/holmes-actions/src/main/java/org/openo/holmes/common/utils/JacksonUtil.java b/holmes-actions/src/main/java/org/openo/holmes/common/utils/JacksonUtil.java new file mode 100644 index 0000000..caef0b0 --- /dev/null +++ b/holmes-actions/src/main/java/org/openo/holmes/common/utils/JacksonUtil.java @@ -0,0 +1,55 @@ +/** + * Copyright 2017 ZTE Corporation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.openo.holmes.common.utils; + +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import java.io.IOException; + +public class JacksonUtil { + + private JacksonUtil() { + + } + + public static String beanToJson(Object obj) throws JsonProcessingException { + ObjectMapper objectMapper = new ObjectMapper(); + return objectMapper.writeValueAsString(obj); + } + + public static T jsonToBean(String json, Class cls) throws IOException { + ObjectMapper objectMapper = new ObjectMapper(); + if (json == null) { + return objectMapper.readValue("{}", cls); + } + return objectMapper.readValue(json, cls); + } + + public static T jsonToBeanByMatchAttribute(String json, Class cls) + throws JsonParseException, + JsonMappingException, IOException { + if (JudgeNullUtil.isEmpty(json)) { + return null; + } + ObjectMapper objectMapper = new ObjectMapper(); + objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + return objectMapper.readValue(json, cls); + } + +} diff --git a/holmes-actions/src/main/java/org/openo/holmes/common/utils/JudgeNullUtil.java b/holmes-actions/src/main/java/org/openo/holmes/common/utils/JudgeNullUtil.java new file mode 100644 index 0000000..beed186 --- /dev/null +++ b/holmes-actions/src/main/java/org/openo/holmes/common/utils/JudgeNullUtil.java @@ -0,0 +1,49 @@ +/** + * Copyright 2017 ZTE Corporation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.openo.holmes.common.utils; + +import java.util.List; + +public class JudgeNullUtil { + + private JudgeNullUtil() { + + } + + public static boolean isEmpty( short[] shorts ) { + return shorts == null || shorts.length == 0; + } + + public static boolean isEmpty( int[] ints ) { + return ints == null || ints.length == 0; + } + + public static boolean isEmpty( long[] longs ) { + return longs == null || longs.length == 0; + } + + public static boolean isEmpty( Object[] obj ) { + return obj == null || obj.length == 0; + } + + public static boolean isEmpty( String str ) { + return str == null || "".equals( str.trim() ); + } + + public static boolean isEmpty( List < ? > list ) { + return list == null || list.isEmpty(); + } +} diff --git a/holmes-actions/src/main/java/org/openo/holmes/common/utils/LanguageUtil.java b/holmes-actions/src/main/java/org/openo/holmes/common/utils/LanguageUtil.java new file mode 100644 index 0000000..484b9a4 --- /dev/null +++ b/holmes-actions/src/main/java/org/openo/holmes/common/utils/LanguageUtil.java @@ -0,0 +1,53 @@ +/** + * Copyright 2017 ZTE Corporation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.openo.holmes.common.utils; + +import java.util.Locale; +import javax.servlet.http.HttpServletRequest; +import org.openo.holmes.common.constant.AlarmConst; + +public class LanguageUtil { + + private LanguageUtil() { + } + + public static String getLanguage(HttpServletRequest servletRequest) { + String language = (String) servletRequest.getHeader("language-option"); + if (JudgeNullUtil.isEmpty(language)) { + language = AlarmConst.ZH_CN; + } + if (language.startsWith(AlarmConst.I18N_ZH)) { + language = AlarmConst.I18N_ZH; + } else if (language.startsWith(AlarmConst.I18N_EN)) { + language = AlarmConst.I18N_EN; + } + return language; + } + + public static Locale getLocale(HttpServletRequest servletRequest) { + String language = (String) servletRequest.getHeader("language-option"); + if (JudgeNullUtil.isEmpty(language)) { + language = AlarmConst.ZH_CN; + } + if (language.startsWith(AlarmConst.I18N_ZH)) { + language = AlarmConst.I18N_ZH; + } else if (language.startsWith(AlarmConst.I18N_EN)) { + language = AlarmConst.I18N_EN; + } + Locale locale = new Locale(language); + return locale; + } +} diff --git a/holmes-actions/src/main/java/org/openo/holmes/common/utils/UserUtil.java b/holmes-actions/src/main/java/org/openo/holmes/common/utils/UserUtil.java new file mode 100644 index 0000000..723b489 --- /dev/null +++ b/holmes-actions/src/main/java/org/openo/holmes/common/utils/UserUtil.java @@ -0,0 +1,35 @@ +/** + * Copyright 2017 ZTE Corporation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.openo.holmes.common.utils; + +import javax.servlet.http.HttpServletRequest; +import org.openo.holmes.common.constant.AlarmConst; + +public class UserUtil { + + private UserUtil() { + + } + + public static String getUserName(HttpServletRequest request) { + String userName = AlarmConst.ADMIN; + String sessionName = (String) request.getHeader("username"); + if (sessionName != null) { + userName = sessionName.toLowerCase(); + } + return userName; + } +} diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..24a3bf8 --- /dev/null +++ b/pom.xml @@ -0,0 +1,137 @@ + + + + + 4.0.0 + + org.openo.oparent + oparent + 1.1.0-SNAPSHOT + ../oparent + + + org.openo.holmes + holmes-actions-parent + pom + holmes-actions-parent + + holmes-actions + + + + UTF-8 + UTF-8 + false + false + ${project.artifactId}-${project.version} + ${basedir}/target + ${project.artifactId}-${project.version} + ${basedir}/../release/pkgzip + **/*$* + https://nexus.open-o.org/content + + + 3.2.1 + 5.1.38 + 0.8.0 + 1.5.3 + 1.16.4 + 2.22.2 + 5.0 + 1.6.1 + 2.2.1 + + + + + io.dropwizard + dropwizard-core + ${dropwizard.version} + provided + + + + io.dropwizard + dropwizard-db + ${dropwizard.version} + + + io.dropwizard + dropwizard-jdbi + ${dropwizard.version} + + + io.swagger + swagger-jersey2-jaxrs + ${swagger.version} + + + + org.projectlombok + lombok + ${lombok.version} + + + mysql + mysql-connector-java + ${mysql.connector.version} + + + + org.antlr + stringtemplate + ${stringtemplate.version} + + + + org.openo.common-services.common-utilities + dropwizard-ioc-container + ${project.version} + + + + + + + + org.quartz-scheduler + quartz + ${quartz.version} + + + org.jdom + jdom + 1.1.3 + + + junit + junit + 4.8.2 + test + + + + org.hamcrest + hamcrest-core + 1.3 + test + + + + org.powermock + powermock-module-junit4 + 1.6.4 + test + + + + + + -- 2.16.6