Skip to content

Commit 0a4b86f

Browse files
authored
use ini file + implement data generator (#1)
* Add SSH config type * Add ini file generation + read configs from it * Delete protobuf dependency * Update dependencies * temp commit * more stuff * add more stuff * add more stuff * fix gitignore
1 parent c536e55 commit 0a4b86f

File tree

136 files changed

+27763
-11640
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

136 files changed

+27763
-11640
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@
1515

1616
.idea/
1717

18-
native-solr-client
18+
go-solr-client
19+
solr-docs-generator

Gopkg.lock

Lines changed: 32 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,6 @@
2424
# go-tests = true
2525
# unused-packages = true
2626

27-
28-
[[constraint]]
29-
name = "github.com/golang/protobuf"
30-
version = "1.1.0"
31-
3227
[[constraint]]
3328
name = "github.com/satori/go.uuid"
3429
version = "1.2.0"

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ GIT_REV_SHORT = $(shell git rev-parse --short HEAD)
1616
install:
1717
go install
1818

19+
build-generator:
20+
go build -ldflags "-X main.GitRevString=$(GIT_REV_SHORT) -X main.Version=$(VERSION) -X main.ActionType=generator" -o solr-docs-generator .
21+
1922
build:
2023
go build -ldflags "-X main.GitRevString=$(GIT_REV_SHORT) -X main.Version=$(VERSION)" .
2124

main.go

Lines changed: 20 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,23 @@ import (
55
"flag"
66
"fmt"
77
"github.com/oleewere/go-solr-client/solr"
8-
"github.com/satori/go.uuid"
8+
"log"
99
)
1010

1111
var Version string
1212
var GitRevString string
13+
var ActionType string
1314

1415
func main() {
1516

16-
var collection string
17-
var url string
18-
var krb5Path string
19-
var keytabPath string
20-
var principal string
21-
var realm string
2217
var isVersionCheck bool
18+
var iniFileLocation string
2319

2420
flag.BoolVar(&isVersionCheck, "version", false, "Print application version and git revision if available")
25-
flag.StringVar(&url, "url", "http://localhost:8983", "URL name for Solr or Solr proxy")
26-
flag.StringVar(&collection, "collection", "hadoop_logs", "Collection name for the Solr client")
27-
flag.StringVar(&krb5Path, "krb-conf-path", "", "Kerberos config location")
28-
flag.StringVar(&keytabPath, "keytab-path", "", "Kerberos keytab location")
29-
flag.StringVar(&principal, "principal", "", "Kerberos principal")
30-
flag.StringVar(&realm, "realm", "", "Kerberos Realm e.g.: EXAMPLE.COM")
21+
flag.StringVar(&iniFileLocation, "ini-file", "", "INI config file location")
22+
if len(ActionType) == 0 {
23+
flag.StringVar(&ActionType, "action-type", "generator", "action")
24+
}
3125

3226
flag.Parse()
3327

@@ -40,14 +34,19 @@ func main() {
4034
os.Exit(0)
4135
}
4236

43-
fmt.Print("Start Solr Cloud Client ...\n")
44-
45-
securityConfig := solr.InitSecurityConfig(krb5Path, keytabPath, principal, realm)
46-
47-
solrConfig := solr.SolrConfig{url, "hadoop_logs", &securityConfig, "/solr",
48-
solr.TLSConfig{}, true, 60}
49-
solrClient, err := solr.NewSolrClient(url, collection, &solrConfig)
37+
if len(iniFileLocation) == 0 {
38+
log.Fatal("INI config file option (--ini-file) is missing.")
39+
}
5040

41+
if _, err := os.Stat(iniFileLocation); os.IsNotExist(err) {
42+
solr.GenerateIniFile(iniFileLocation)
43+
os.Exit(0)
44+
}
45+
log.Println("Starting Solr Client ...")
46+
solrConfig, sshConfig := solr.GenerateSolrConfig(iniFileLocation)
47+
solr.GenerateSolrData(&solrConfig, &sshConfig, iniFileLocation)
48+
/*
49+
solrClient, err := solr.NewSolrClient(&solrConfig)
5150
_, response, _ := solrClient.Query(nil)
5251
docs := response.Response.Docs
5352
for _, doc := range docs {
@@ -58,29 +57,5 @@ func main() {
5857
}
5958
fmt.Printf("----------------------")
6059
}
61-
62-
putDocs := solr.SolrDocuments{
63-
solr.SolrDocument{
64-
"id": uuid.NewV4(),
65-
"log_message": "[email protected]",
66-
"seq_num": 100,
67-
"level": "FATAL",
68-
"logtime": "2018-07-03T15:55:47.396Z",
69-
},
70-
solr.SolrDocument{
71-
"id": uuid.NewV4(),
72-
"log_message": "[email protected]",
73-
"seq_num": 1000,
74-
"level": "FATAL",
75-
"logtime": "2018-07-03T15:55:47.396Z",
76-
},
77-
}
78-
79-
solrClient.Update(putDocs, nil, false)
80-
81-
if err != nil {
82-
fmt.Print(err)
83-
}
84-
85-
os.Exit(0)
60+
*/
8661
}

solr-client-sample.cfg

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Copyright 2018 Oliver Szabo
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
[security]
16+
kerberosEnabled = false
17+
kerberosKeytab = /tmp/solr.keytab
18+
kerberosPrincipal = solr/myhostname
19+
kerberosRealm = EXAMPLE.COM
20+
kerberosKrb5Path = /tmp/krb5.conf
21+
22+
[solr]
23+
url = http://localhost:8983
24+
context = /solr
25+
collection = hadoop_logs
26+
ssl = false
27+
connection_timeout = 60
28+
29+
[ssh]
30+
enabled = false
31+
username = root
32+
hostname = myremotehost
33+
private_key_path = /keys/private_key
34+
download_location = /tmp
35+
remote_krb5_conf = /etc/krb5.conf
36+
remote_keytab = /etc/security/keytabs/solr.service.keytab
37+
38+
[generator]
39+
num_writes = 10
40+
num_docs_per_write = 1000
41+
cluster_field = cluster
42+
cluster_num = 10
43+
filterable_field = host
44+
filterable_field_num = 1000
45+
level_field = level
46+
level_values = INFO,DEBUG,FATAL,WARN,ERROR,UNKNOWN,TRACE
47+
type_field = type
48+
type_values = ambari_server,ambari_agent,ambari_config,ambari_eclipselink,hdfs_name_node,hdfs_secondary_name_node
49+
date_field = logtime
50+
message_fields = log_message
51+
num_fields = seq_num

solr-client.cfg

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
[security]
2+
kerberosEnabled = true
3+
kerberosKeytab = /tmp/solr.keytab
4+
kerberosPrincipal = infra-solr/c7402.ambari.apache.org
5+
kerberosRealm = AMBARI.APACHE.ORG
6+
kerberosKrb5Path = /tmp/krb5.conf
7+
8+
[solr]
9+
url = http://c7402.ambari.apache.org:8886
10+
context = /solr
11+
collection = hadoop_logs
12+
ssl = false
13+
connection_timeout = 60
14+
15+
[ssh]
16+
enabled = true
17+
username = root
18+
hostname = c7402.ambari.apache.org
19+
private_key_path = /Users/oliverszabo/Projects/ambari-vagrant/centos7.4/insecure_private_key
20+
download_location = /tmp
21+
remote_krb5_conf = /etc/krb5.conf
22+
remote_keytab = /etc/security/keytabs/ambari-infra-solr.service.keytab
23+
24+
[generator]
25+
num_writes = 10
26+
num_docs_per_write = 1000
27+
cluster_field = cluster
28+
cluster_num = 10
29+
filterable_field = host
30+
filterable_field_num = 1000
31+
level_field = level
32+
level_values = INFO,DEBUG,FATAL,WARN,ERROR,UNKNOWN,TRACE
33+
type_field = type
34+
type_values = ambari_server,ambari_agent,ambari_config,ambari_eclipselink,hdfs_name_node,hdfs_secondary_name_node
35+
date_field = logtime
36+
message_fields = log_message
37+
num_fields = seq_num

solr/client.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828
"time"
2929
)
3030

31-
func NewSolrClient(url string, collection string, solrConfig *SolrConfig) (*SolrClient, error) {
31+
func NewSolrClient(solrConfig *SolrConfig) (*SolrClient, error) {
3232
httpClient := &http.Client{
3333
Transport: &http.Transport{
3434
Proxy: http.ProxyFromEnvironment,
@@ -38,9 +38,6 @@ func NewSolrClient(url string, collection string, solrConfig *SolrConfig) (*Solr
3838
ResponseHeaderTimeout: 10 * time.Second,
3939
},
4040
}
41-
solrConfig.Collection = collection
42-
solrConfig.Url = url
43-
solrConfig.SolrUrlContext = "/solr"
4441

4542
securityConfig := solrConfig.SecurityConfig
4643

0 commit comments

Comments
 (0)