Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unify generator #3452

Merged
merged 2 commits into from
Feb 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ matrix:

# Generators
- os: linux
env: TARGETS="-C generate/metricbeat test"
env: TARGETS="-C generator/metricbeat test"
go: *go_version
- os: linux
env: TARGETS="-C generate/beat test"
env: TARGETS="-C generator/beat test"
go: *go_version

addons:
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ https://github.com/elastic/beats/compare/v5.1.1...master[Check the HEAD diff]

*Affecting all Beats*

- Change beat generator. Use `$GOPATH/src/github.com/elastic/beats/script/generate.py` to generate a beat. {pull}3452[3452]

*Metricbeat*

*Packetbeat*
Expand Down
8 changes: 3 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ SNAPSHOT?=yes
.PHONY: testsuite
testsuite:
$(foreach var,$(PROJECTS),$(MAKE) -C $(var) testsuite || exit 1;)
#$(MAKE) -C generate test
#$(MAKE) -C generator test

stop-environments:
$(foreach var,$(PROJECTS_ENV),$(MAKE) -C $(var) stop-environment || exit 0;)
Expand Down Expand Up @@ -46,13 +46,13 @@ update:
clean:
rm -rf build
$(foreach var,$(PROJECTS),$(MAKE) -C $(var) clean || exit 1;)
$(MAKE) -C generate clean
$(MAKE) -C generator clean

# Cleans up the vendor directory from unnecessary files
# This should always be run after updating the dependencies
.PHONY: clean-vendor
clean-vendor:
sh scripts/clean_vendor.sh
sh script/clean_vendor.sh

.PHONY: check
check:
Expand Down Expand Up @@ -118,5 +118,3 @@ upload-release:
.PHONY: notice
notice:
python dev-tools/generate_notice.py .


7 changes: 0 additions & 7 deletions generate/beat.py

This file was deleted.

7 changes: 0 additions & 7 deletions generate/metricbeat.py

This file was deleted.

52 changes: 0 additions & 52 deletions generate/metricbeat/Makefile

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions generator/beat/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@


include ../common/Makefile
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
24 changes: 14 additions & 10 deletions generate/beat/Makefile → generator/common/Makefile
Original file line number Diff line number Diff line change
@@ -1,31 +1,35 @@
BUILD_DIR?=build
PWD=$(shell pwd)
PYTHON_ENV?=${BUILD_DIR}/python-env/
PYTHON_ENV?=${BUILD_DIR}/python-env
BEAT_TYPE?=beat
BEAT_PATH=${BUILD_DIR}/src/beatpath/testbeat
ES_BEATS=${GOPATH}/src/github.com/elastic/beats
PREPARE_COMMAND?=

# Runs test build for mock beat
.PHONY: test
test: python-env

# Makes sure to use current version of beats for testing
mkdir -p ${BUILD_DIR}/src/github.com/elastic/beats/
rsync -a --exclude=build ${PWD}/../../* ${BUILD_DIR}/src/github.com/elastic/beats/

mkdir -p ${BEAT_PATH}
export GOPATH=${PWD}/build ; \
. ${PYTHON_ENV}/bin/activate && python ${PWD}/build/src/github.com/elastic/beats/generate/beat.py --project_name=Testbeat --github_name=ruflin --beat_path=beatpath/testbeat --full_name="Nicolas Ruflin"
test: prepare-test

. ${PYTHON_ENV}/bin/activate; \
export GOPATH=${PWD}/build ; \
export PATH=${PATH}:${PWD}/build/bin; \
cd ${BEAT_PATH} ; \
make copy-vendor ; \
${PREPARE_COMMAND} \
make check ; \
make update ; \
make ; \
make unit

prepare-test: python-env
# Makes sure to use current version of beats for testing
mkdir -p ${BUILD_DIR}/src/github.com/elastic/beats/
rsync -a --exclude=build ${PWD}/../../* ${BUILD_DIR}/src/github.com/elastic/beats/

mkdir -p ${BEAT_PATH}
export GOPATH=${PWD}/build ; \
. ${PYTHON_ENV}/bin/activate && python ${PWD}/build/src/github.com/elastic/beats/script/generate.py --type=${BEAT_TYPE} --project_name=Testbeat --github_name=ruflin --beat_path=beatpath/testbeat --full_name="Nicolas Ruflin"

# Runs test build for the created beat
.PHONY: test-build
test-build: test
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions generator/metricbeat/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
BEAT_TYPE=metricbeat
PREPARE_COMMAND=MODULE=elastic METRICSET=test make create-metricset ;

include ../common/Makefile

File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion libbeat/docs/newbeat.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ Run python and specify the path to the Beat generator:

[source,shell]
--------------------
python $GOPATH/src/github.com/elastic/beats/generate/beat.py
python $GOPATH/src/github.com/elastic/beats/script/generate.py
--------------------

Python will prompt you to enter information about your Beat. For the `project_name`, enter `Countbeat`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Run the command:

[source,bash]
----
python ${GOPATH}/src/github.com/elastic/beats/generate/metricbeat.py
python ${GOPATH}/src/github.com/elastic/beats/script/generate.py --type=metricbeat
----

When prompted, enter the Beat name and path.
Expand Down
File renamed without changes.
26 changes: 19 additions & 7 deletions generate/helper.py → script/generate.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import argparse

# Creates a new beat based on the given parameters
# Creates a new beat or metricbeat based on the given parameters

project_name = ""
github_name = ""
Expand All @@ -10,7 +10,8 @@
full_name = ""


def generate_beat(template_path, args):
def generate_beat(args):


global project_name, github_name, beat, beat_path, full_name

Expand All @@ -27,7 +28,7 @@ def generate_beat(template_path, args):
full_name = args.full_name

read_input()
process_file(template_path)
process_file(args.type)


def read_input():
Expand All @@ -50,13 +51,13 @@ def read_input():
full_name = raw_input("Firstname Lastname: ") or "Firstname Lastname"


def process_file(template_path):
def process_file(beat_type):

# Load path information
generator_path = os.path.dirname(os.path.realpath(__file__))
template_path = os.path.dirname(os.path.realpath(__file__)) + '/../generator'
go_path = os.environ['GOPATH']

for root, dirs, files in os.walk(generator_path + '/' + template_path + '/{beat}'):
for root, dirs, files in os.walk(template_path + '/' + beat_type + '/{beat}'):

for file in files:

Expand All @@ -74,7 +75,7 @@ def process_file(template_path):
new_path = replace_variables(full_path).replace(".go.tmpl", ".go")

# remove generator info and beat name from path
file_path = new_path.replace(generator_path + "/" + template_path + "/" + beat, "")
file_path = new_path.replace(template_path + "/" + beat_type + "/" + beat, "")

# New file path to write file content to
write_file = go_path + "/src/" + beat_path + "/" + file_path
Expand Down Expand Up @@ -108,5 +109,16 @@ def get_parser():
parser.add_argument("--github_name", help="Github name")
parser.add_argument("--beat_path", help="Beat path")
parser.add_argument("--full_name", help="Full name")
parser.add_argument("--type", help="Beat type", default="beat")

return parser


if __name__ == "__main__":

parser = get_parser()
args = parser.parse_args()

generate_beat(args)