octocore-cassandra 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGES.md +12 -0
- data/CONTRIBUTING +0 -0
- data/Gemfile +10 -0
- data/LICENSE +202 -0
- data/MAINTAINERS +0 -0
- data/NOTICE +8 -0
- data/README.md +69 -0
- data/Rakefile +142 -0
- data/bin/fakestream-cassandra +258 -0
- data/bin/octocore-admin-cassandra +54 -0
- data/lib/octocore-cassandra.rb +152 -0
- data/lib/octocore-cassandra/baseline.rb +131 -0
- data/lib/octocore-cassandra/callbacks.rb +117 -0
- data/lib/octocore-cassandra/config.rb +39 -0
- data/lib/octocore-cassandra/config/config.yml +1 -0
- data/lib/octocore-cassandra/config/search/index/user.yml +42 -0
- data/lib/octocore-cassandra/counter.rb +265 -0
- data/lib/octocore-cassandra/counter/helpers.rb +168 -0
- data/lib/octocore-cassandra/email.rb +63 -0
- data/lib/octocore-cassandra/featureflag.rb +79 -0
- data/lib/octocore-cassandra/helpers.rb +6 -0
- data/lib/octocore-cassandra/helpers/api_consumer_helper.rb +51 -0
- data/lib/octocore-cassandra/helpers/api_helper.rb +65 -0
- data/lib/octocore-cassandra/helpers/api_logger.rb +14 -0
- data/lib/octocore-cassandra/helpers/client_helper.rb +104 -0
- data/lib/octocore-cassandra/helpers/kong_helper.rb +164 -0
- data/lib/octocore-cassandra/helpers/sinatra_helper.rb +22 -0
- data/lib/octocore-cassandra/kafka_bridge.rb +60 -0
- data/lib/octocore-cassandra/kldivergence.rb +14 -0
- data/lib/octocore-cassandra/mailer.rb +1 -0
- data/lib/octocore-cassandra/mailer/subscriber_mailer.rb +30 -0
- data/lib/octocore-cassandra/message_parser.rb +114 -0
- data/lib/octocore-cassandra/models.rb +274 -0
- data/lib/octocore-cassandra/models/contactus.rb +42 -0
- data/lib/octocore-cassandra/models/enterprise.rb +76 -0
- data/lib/octocore-cassandra/models/enterprise/adapter_details.rb +18 -0
- data/lib/octocore-cassandra/models/enterprise/api_event.rb +14 -0
- data/lib/octocore-cassandra/models/enterprise/api_hit.rb +20 -0
- data/lib/octocore-cassandra/models/enterprise/api_key.rb +11 -0
- data/lib/octocore-cassandra/models/enterprise/api_track.rb +13 -0
- data/lib/octocore-cassandra/models/enterprise/app_init.rb +13 -0
- data/lib/octocore-cassandra/models/enterprise/app_login.rb +12 -0
- data/lib/octocore-cassandra/models/enterprise/app_logout.rb +12 -0
- data/lib/octocore-cassandra/models/enterprise/authorization.rb +67 -0
- data/lib/octocore-cassandra/models/enterprise/category.rb +14 -0
- data/lib/octocore-cassandra/models/enterprise/category_baseline.rb +19 -0
- data/lib/octocore-cassandra/models/enterprise/category_hit.rb +26 -0
- data/lib/octocore-cassandra/models/enterprise/category_trend.rb +19 -0
- data/lib/octocore-cassandra/models/enterprise/conversions.rb +69 -0
- data/lib/octocore-cassandra/models/enterprise/ctr.rb +54 -0
- data/lib/octocore-cassandra/models/enterprise/dimension_choice.rb +21 -0
- data/lib/octocore-cassandra/models/enterprise/engagement_time.rb +43 -0
- data/lib/octocore-cassandra/models/enterprise/funnel_data.rb +20 -0
- data/lib/octocore-cassandra/models/enterprise/funnel_tracker.rb +19 -0
- data/lib/octocore-cassandra/models/enterprise/funnels.rb +129 -0
- data/lib/octocore-cassandra/models/enterprise/gcm.rb +21 -0
- data/lib/octocore-cassandra/models/enterprise/newsfeed_hit.rb +52 -0
- data/lib/octocore-cassandra/models/enterprise/notification_hit.rb +42 -0
- data/lib/octocore-cassandra/models/enterprise/page.rb +15 -0
- data/lib/octocore-cassandra/models/enterprise/page_view.rb +14 -0
- data/lib/octocore-cassandra/models/enterprise/pageload_time.rb +43 -0
- data/lib/octocore-cassandra/models/enterprise/product.rb +22 -0
- data/lib/octocore-cassandra/models/enterprise/product_baseline.rb +20 -0
- data/lib/octocore-cassandra/models/enterprise/product_hit.rb +26 -0
- data/lib/octocore-cassandra/models/enterprise/product_page_view.rb +13 -0
- data/lib/octocore-cassandra/models/enterprise/product_trend.rb +18 -0
- data/lib/octocore-cassandra/models/enterprise/push_key.rb +15 -0
- data/lib/octocore-cassandra/models/enterprise/rules.rb +45 -0
- data/lib/octocore-cassandra/models/enterprise/segment.rb +65 -0
- data/lib/octocore-cassandra/models/enterprise/segment_data.rb +22 -0
- data/lib/octocore-cassandra/models/enterprise/tag.rb +14 -0
- data/lib/octocore-cassandra/models/enterprise/tag_baseline.rb +19 -0
- data/lib/octocore-cassandra/models/enterprise/tag_hit.rb +26 -0
- data/lib/octocore-cassandra/models/enterprise/tag_trend.rb +19 -0
- data/lib/octocore-cassandra/models/enterprise/template.rb +18 -0
- data/lib/octocore-cassandra/models/plans.rb +17 -0
- data/lib/octocore-cassandra/models/subscribe.rb +13 -0
- data/lib/octocore-cassandra/models/user.rb +15 -0
- data/lib/octocore-cassandra/models/user/push_token.rb +15 -0
- data/lib/octocore-cassandra/models/user/user_browser_details.rb +16 -0
- data/lib/octocore-cassandra/models/user/user_location_history.rb +15 -0
- data/lib/octocore-cassandra/models/user/user_persona.rb +101 -0
- data/lib/octocore-cassandra/models/user/user_phone_details.rb +17 -0
- data/lib/octocore-cassandra/models/user/user_profile.rb +20 -0
- data/lib/octocore-cassandra/models/user/user_timeline.rb +111 -0
- data/lib/octocore-cassandra/record.rb +20 -0
- data/lib/octocore-cassandra/schedeuleable.rb +20 -0
- data/lib/octocore-cassandra/scheduler.rb +72 -0
- data/lib/octocore-cassandra/search.rb +5 -0
- data/lib/octocore-cassandra/search/client.rb +33 -0
- data/lib/octocore-cassandra/search/indexer.rb +0 -0
- data/lib/octocore-cassandra/search/searchable.rb +18 -0
- data/lib/octocore-cassandra/search/setup.rb +71 -0
- data/lib/octocore-cassandra/segment.rb +287 -0
- data/lib/octocore-cassandra/stats.rb +33 -0
- data/lib/octocore-cassandra/trendable.rb +88 -0
- data/lib/octocore-cassandra/trends.rb +158 -0
- data/lib/octocore-cassandra/utils.rb +90 -0
- data/lib/octocore-cassandra/version.rb +4 -0
- data/spec/lib/stats_spec.rb +20 -0
- data/spec/spec_helper.rb +103 -0
- metadata +490 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 713927391e13bd6efae1311499cf5b951b6d52eb
|
4
|
+
data.tar.gz: c0a63bf219fefe45f9ce666c8f8ec49b96a1f46a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 46c32c83f92701e8e77031c0a581404655615779685668fb8d020546b19ff3460d3d4488fcff0053bbd4a643da304112ab7667cf096f2b26b6e5cb7f6c96e07a
|
7
|
+
data.tar.gz: e64f06f4b74fcbf2164d522242f9fb6d38d5481d8ff92d1afb086949f4658d581f8348014c1538eff88d438b29de60eaf8b606a46687ce4e469052ad7d1f5d6d
|
data/CHANGES.md
ADDED
data/CONTRIBUTING
ADDED
File without changes
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,202 @@
|
|
1
|
+
|
2
|
+
Apache License
|
3
|
+
Version 2.0, January 2004
|
4
|
+
http://www.apache.org/licenses/
|
5
|
+
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
7
|
+
|
8
|
+
1. Definitions.
|
9
|
+
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
12
|
+
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
14
|
+
the copyright owner that is granting the License.
|
15
|
+
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
17
|
+
other entities that control, are controlled by, or are under common
|
18
|
+
control with that entity. For the purposes of this definition,
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
20
|
+
direction or management of such entity, whether by contract or
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
23
|
+
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
25
|
+
exercising permissions granted by this License.
|
26
|
+
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
28
|
+
including but not limited to software source code, documentation
|
29
|
+
source, and configuration files.
|
30
|
+
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
32
|
+
transformation or translation of a Source form, including but
|
33
|
+
not limited to compiled object code, generated documentation,
|
34
|
+
and conversions to other media types.
|
35
|
+
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
37
|
+
Object form, made available under the License, as indicated by a
|
38
|
+
copyright notice that is included in or attached to the work
|
39
|
+
(an example is provided in the Appendix below).
|
40
|
+
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
47
|
+
the Work and Derivative Works thereof.
|
48
|
+
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
50
|
+
the original version of the Work and any modifications or additions
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
62
|
+
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
65
|
+
subsequently incorporated within the Work.
|
66
|
+
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
73
|
+
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
79
|
+
where such license applies only to those patent claims licensable
|
80
|
+
by such Contributor that are necessarily infringed by their
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
83
|
+
institute patent litigation against any entity (including a
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
86
|
+
or contributory patent infringement, then any patent licenses
|
87
|
+
granted to You under this License for that Work shall terminate
|
88
|
+
as of the date such litigation is filed.
|
89
|
+
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
92
|
+
modifications, and in Source or Object form, provided that You
|
93
|
+
meet the following conditions:
|
94
|
+
|
95
|
+
(a) You must give any other recipients of the Work or
|
96
|
+
Derivative Works a copy of this License; and
|
97
|
+
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
99
|
+
stating that You changed the files; and
|
100
|
+
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
103
|
+
attribution notices from the Source form of the Work,
|
104
|
+
excluding those notices that do not pertain to any part of
|
105
|
+
the Derivative Works; and
|
106
|
+
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
109
|
+
include a readable copy of the attribution notices contained
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
112
|
+
of the following places: within a NOTICE text file distributed
|
113
|
+
as part of the Derivative Works; within the Source form or
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
115
|
+
within a display generated by the Derivative Works, if and
|
116
|
+
wherever such third-party notices normally appear. The contents
|
117
|
+
of the NOTICE file are for informational purposes only and
|
118
|
+
do not modify the License. You may add Your own attribution
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
121
|
+
that such additional attribution notices cannot be construed
|
122
|
+
as modifying the License.
|
123
|
+
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
125
|
+
may provide additional or different license terms and conditions
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
129
|
+
the conditions stated in this License.
|
130
|
+
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
134
|
+
this License, without any additional terms or conditions.
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
136
|
+
the terms of any separate license agreement you may have executed
|
137
|
+
with Licensor regarding such Contributions.
|
138
|
+
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
141
|
+
except as required for reasonable and customary use in describing the
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
143
|
+
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
153
|
+
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
159
|
+
incidental, or consequential damages of any character arising as a
|
160
|
+
result of this License or out of the use or inability to use the
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
163
|
+
other commercial damages or losses), even if such Contributor
|
164
|
+
has been advised of the possibility of such damages.
|
165
|
+
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
169
|
+
or other liability obligations and/or rights consistent with this
|
170
|
+
License. However, in accepting such obligations, You may act only
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
175
|
+
of your accepting any such warranty or additional liability.
|
176
|
+
|
177
|
+
END OF TERMS AND CONDITIONS
|
178
|
+
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
180
|
+
|
181
|
+
To apply the Apache License to your work, attach the following
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
183
|
+
replaced with your own identifying information. (Don't include
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
185
|
+
comment syntax for the file format. We also recommend that a
|
186
|
+
file or class name and description of purpose be included on the
|
187
|
+
same "printed page" as the copyright notice for easier
|
188
|
+
identification within third-party archives.
|
189
|
+
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
191
|
+
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
193
|
+
you may not use this file except in compliance with the License.
|
194
|
+
You may obtain a copy of the License at
|
195
|
+
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
197
|
+
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
201
|
+
See the License for the specific language governing permissions and
|
202
|
+
limitations under the License.
|
data/MAINTAINERS
ADDED
File without changes
|
data/NOTICE
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
Octo.ai, (C) 2015,2016 Aurora Borealis Technologies Pvt. Ltd.
|
2
|
+
|
3
|
+
This product includes software developed at Aurora Borealis Technologies Pvt. Ltd (https://octo.ai/).
|
4
|
+
|
5
|
+
The Octoai project contains unmodified/modified subcomponents too with
|
6
|
+
separate copyright notices and license terms. Your use of the source
|
7
|
+
code for these subcomponents is subject to the terms and conditions
|
8
|
+
of the following licenses.
|
data/README.md
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
# octocore-cassandra
|
2
|
+
|
3
|
+
This is the Octomatic Enterprise Core gem. It provides most of the ORM stuff for Cassandra. Class and modules for different tables.
|
4
|
+
|
5
|
+
## Installting
|
6
|
+
|
7
|
+
```bash
|
8
|
+
gem install octocore-cassandra
|
9
|
+
```
|
10
|
+
|
11
|
+
In case you are using bundler, you need to add something like this to your Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'octocore-cassandra', :git => 'git@github.com:octoai/gem-octocore-cassandra.git'
|
15
|
+
```
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
## DB Migrations
|
20
|
+
|
21
|
+
### OctoAdmin CLI
|
22
|
+
|
23
|
+
This gem comes with a handy utility called `octocore-admin`. You can use this utility for db migrations, reset and init.
|
24
|
+
|
25
|
+
```bash
|
26
|
+
$ octocore-admin action path/to/config/dir
|
27
|
+
```
|
28
|
+
|
29
|
+
Where
|
30
|
+
|
31
|
+
- `action`: The action to be performed. One of `init`, `migrate` or `reset`
|
32
|
+
- `/path/to/config/dir`: The path where your config dir is placed
|
33
|
+
|
34
|
+
|
35
|
+
# Development
|
36
|
+
|
37
|
+
## Clone the repo
|
38
|
+
|
39
|
+
`$ git clone git@github.com:octoai/gem-octocore.git`
|
40
|
+
|
41
|
+
## Building
|
42
|
+
|
43
|
+
```bash
|
44
|
+
$ ./bin/clean_setup.sh
|
45
|
+
```
|
46
|
+
|
47
|
+
## Specs
|
48
|
+
|
49
|
+
```bash
|
50
|
+
$ rake spec
|
51
|
+
```
|
52
|
+
|
53
|
+
# Verifying connectivity
|
54
|
+
|
55
|
+
You can use the following set of commands in `irb` to verify all things working with this gem. Execute it from irb in PROJ_DIR.
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
require 'octocore'
|
59
|
+
config_dir = '/path/to/config/dir'
|
60
|
+
Octo.connect_with_config_file config_dir
|
61
|
+
```
|
62
|
+
|
63
|
+
# Creating fake stream
|
64
|
+
|
65
|
+
It ships with a utility called `fakestream`. It will automatically stream random data. To use just open your console and type
|
66
|
+
|
67
|
+
```bash
|
68
|
+
$ fakestream /path/to/config/dir
|
69
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
require 'cequel'
|
2
|
+
require 'yaml'
|
3
|
+
require 'redis'
|
4
|
+
require 'rspec/core/rake_task'
|
5
|
+
|
6
|
+
require 'octocore/helpers/kong_helper'
|
7
|
+
require 'octocore/config'
|
8
|
+
|
9
|
+
RSpec::Core::RakeTask.new('spec')
|
10
|
+
|
11
|
+
task :environment do
|
12
|
+
config_dir = ENV['CONFIG_DIR'] || 'lib/octocore/config/'
|
13
|
+
config = {}
|
14
|
+
Dir[config_dir + '**{,/*/**}/*.yml'].each do |file|
|
15
|
+
_config = YAML.load_file(file)
|
16
|
+
if _config
|
17
|
+
puts "loading from file: #{ file }"
|
18
|
+
config = config.merge(_config.deep_symbolize_keys)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
Octo.load_config config
|
22
|
+
connection = Cequel.connect(Octo.get_config(:cassandra))
|
23
|
+
Cequel::Record.connection = connection
|
24
|
+
end
|
25
|
+
|
26
|
+
# Load default tasks from Cequel
|
27
|
+
spec = Gem::Specification.find_by_name 'cequel'
|
28
|
+
load "#{spec.gem_dir}/lib/cequel/record/tasks.rb"
|
29
|
+
|
30
|
+
# Remove those tasks from cequel which we shall override
|
31
|
+
%w(cequel:init cequel:migrate cequel:reset).each do |t|
|
32
|
+
Rake.application.instance_variable_get('@tasks').delete(t)
|
33
|
+
end
|
34
|
+
|
35
|
+
# Overriding rake actions
|
36
|
+
namespace :octo do
|
37
|
+
|
38
|
+
desc 'Create keyspace and tables for all defined models'
|
39
|
+
task :init => %w(environment cequel:keyspace:create octo:migrate)
|
40
|
+
|
41
|
+
desc 'Drop keyspace if exists, then create and migrate'
|
42
|
+
task :reset => :environment do
|
43
|
+
kong_delete
|
44
|
+
clear_cache
|
45
|
+
if Cequel::Record.connection.schema.exists?
|
46
|
+
task('cequel:keyspace:drop').invoke
|
47
|
+
end
|
48
|
+
task('cequel:keyspace:create').invoke
|
49
|
+
migrate
|
50
|
+
end
|
51
|
+
|
52
|
+
desc "Synchronize all models defined in `lib/octocore/models' with Cassandra " \
|
53
|
+
"database schema"
|
54
|
+
task :migrate => :environment do
|
55
|
+
migrate
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
# Delete Kong Consumers and Apis
|
60
|
+
def kong_delete
|
61
|
+
kong_config = Octo.get_config :kong
|
62
|
+
if kong_config[:enabled]
|
63
|
+
Octo::Helpers::KongBridge.delete_all
|
64
|
+
puts 'Kong Cleaned'
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
# Clear Cache
|
69
|
+
def clear_cache
|
70
|
+
default_cache = {
|
71
|
+
host: '127.0.0.1', port: 6379
|
72
|
+
}
|
73
|
+
redis = Redis.new(default_cache.merge(driver: :hiredis))
|
74
|
+
redis.flushall
|
75
|
+
puts 'Cache Cleaned'
|
76
|
+
end
|
77
|
+
|
78
|
+
def migrate
|
79
|
+
watch_stack = ActiveSupport::Dependencies::WatchStack.new
|
80
|
+
|
81
|
+
migration_table_names = Set[]
|
82
|
+
|
83
|
+
classes = Set[]
|
84
|
+
|
85
|
+
project_root = Dir.pwd
|
86
|
+
models_dir_path = "#{File.expand_path('lib/octocore/models', project_root)}/"
|
87
|
+
model_files = Dir.glob(File.join(models_dir_path, '**', '*.rb'))
|
88
|
+
|
89
|
+
model_files.sort.each do |file|
|
90
|
+
watch_namespaces = ["Object"]
|
91
|
+
model_file_name = file.sub(/^#{Regexp.escape(models_dir_path)}/, "")
|
92
|
+
dirname = File.dirname(model_file_name)
|
93
|
+
watch_namespaces << dirname.classify unless dirname == "."
|
94
|
+
watch_stack.watch_namespaces(watch_namespaces)
|
95
|
+
|
96
|
+
require_dependency(file)
|
97
|
+
|
98
|
+
new_constants = watch_stack.new_constants
|
99
|
+
if new_constants.empty?
|
100
|
+
_new = model_file_name.sub(/\.rb$/, "")
|
101
|
+
if Octo.constants.include?_new.classify.to_sym
|
102
|
+
new_constants << "Octo"
|
103
|
+
else
|
104
|
+
new_constants << "Octo"
|
105
|
+
#new_constants << _new.classify
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
new_constants.each do |class_name|
|
110
|
+
begin
|
111
|
+
clazz = class_name.constantize
|
112
|
+
rescue LoadError, RuntimeError, NameError => e
|
113
|
+
puts e
|
114
|
+
else
|
115
|
+
if clazz.is_a?(Class)
|
116
|
+
if clazz.ancestors.include?(Cequel::Record) &&
|
117
|
+
!migration_table_names.include?(clazz.table_name.to_sym)
|
118
|
+
clazz.synchronize_schema
|
119
|
+
migration_table_names << clazz.table_name.to_sym
|
120
|
+
puts "** Synchronized schema for #{class_name}"
|
121
|
+
end
|
122
|
+
elsif clazz.is_a?(Module)
|
123
|
+
method_name = :constants
|
124
|
+
clazzes = clazz.public_send(method_name) if clazz.respond_to? method_name
|
125
|
+
clazzes.each do |_clazz|
|
126
|
+
_cls = clazz.const_get(_clazz)
|
127
|
+
if _cls.is_a?(Class) and !classes.include?_cls
|
128
|
+
if _cls.ancestors.include?(Cequel::Record) &&
|
129
|
+
!migration_table_names.include?(_cls.table_name.to_sym)
|
130
|
+
_cls.synchronize_schema
|
131
|
+
migration_table_names << _cls.table_name.to_sym
|
132
|
+
puts "Synchronized schema for #{_cls}"
|
133
|
+
classes << _cls
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|