Skip to content

Commit

Permalink
[Feat] execute [python -m webmeter jmeter_server=on] to start jemter-…
Browse files Browse the repository at this point in the history
…server file
  • Loading branch information
rafa0128 committed Nov 20, 2023
1 parent 2f1702d commit cb84da6
Show file tree
Hide file tree
Showing 12 changed files with 62 additions and 34 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
setuptools.setup(
install_requires=['fastapi','uvicorn', 'requests', 'loguru', 'fire','pyfiglet','psutil',
'pyyaml','python-multipart','sqlalchemy'],
version='1.0.14',
version='1.0.15',
python_requires='>=3.10',
long_description=long_description,
long_description_content_type="text/markdown",
Expand Down
26 changes: 18 additions & 8 deletions webmeter/core/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import datetime
from loguru import logger
from typing import Optional
from core.utils import Common, Platform
from core.sqlhandle import crud
from core.task import TaskBase
from webmeter.core.utils import Common, Platform
from webmeter.core.sqlhandle import crud
from webmeter.core.task import TaskBase

class EngineServie(TaskBase):

Expand All @@ -16,12 +16,25 @@ class EngineServie(TaskBase):
'linux': os.path.join(JMETER_DIR, 'bin', 'jmeter.sh')
}

JMETER_SERVER_PATH = {
'windows': os.path.join(JMETER_DIR, 'bin', 'jmeter-server.bat'),
'macos': os.path.join(JMETER_DIR, 'bin', 'jmeter-server'),
'linux': os.path.join(JMETER_DIR, 'bin', 'jmeter-server')
}

@classmethod
def check_JavaEnvironment(cls):
result = Common.exec_cmd('java -version')
if result != 0:
logger.error('Please download java (https://www.java.com/)')
raise Exception('No java version found')
raise Exception('No JAVA_HOME found')
return result

@classmethod
def check_JmeterEnvironment(cls):
result = Common.exec_cmd('jmeter -v')
if result != 0:
raise Exception('No JMETER_HOME found')
return result

@classmethod
Expand Down Expand Up @@ -127,10 +140,7 @@ def run(cls, content: dict, model='local') -> int:
'status': 'Done'
})
else:
crud.update_task(tasks={
'task': task_format,
'status': 'Error'
})
crud.update_task(tasks={'task': task_format,'status': 'Error'})
logger.error('remote_host connect failed')
else:
logger.error('task is failed')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ gui.quick_9=ViewResultsFullVisualizer
#---------------------------------------------------------------------------

# Remote Hosts - comma delimited
# remote_hosts={host}:1099,{host}:1099
#remote_hosts={host1}:1099,{host2}:1099

# RMI port to be used by the server (must start rmiregistry with same port)
#server_port=1099
Expand Down
2 changes: 1 addition & 1 deletion webmeter/core/plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import shutil
from loguru import logger
from fastapi import UploadFile
from core.utils import Common, JMX
from webmeter.core.utils import Common, JMX


class Base(object):
Expand Down
4 changes: 2 additions & 2 deletions webmeter/core/sqlhandle/crud.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from typing import Optional
from loguru import logger
import os, shutil, datetime
from core.sqlhandle import models, schemas, database
from core.plan import TestPlan
from webmeter.core.sqlhandle import models, schemas, database
from webmeter.core.plan import TestPlan

def create_task(tasks: dict):
with database.dbConnect() as session:
Expand Down
2 changes: 1 addition & 1 deletion webmeter/core/sqlhandle/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from contextlib import contextmanager
from loguru import logger
import os
from core.utils import Common
from webmeter.core.utils import Common

SQL_DIR = Common.make_dir(os.path.join(os.getcwd(), 'webmeter'))
SQLALCHEMY_DATABASE_URL = "sqlite:///{}/app.db".format(SQL_DIR)
Expand Down
2 changes: 1 addition & 1 deletion webmeter/core/sqlhandle/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from sqlalchemy import Boolean, Column, Integer, String, DateTime, Float
from core.sqlhandle.database import Base
from webmeter.core.sqlhandle.database import Base


class Task(Base):
Expand Down
4 changes: 2 additions & 2 deletions webmeter/core/task.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from loguru import logger
import json, os
from typing import Optional
from core.utils import Common
from core.sqlhandle import crud
from webmeter.core.utils import Common
from webmeter.core.sqlhandle import crud


class TaskBase(object):
Expand Down
17 changes: 13 additions & 4 deletions webmeter/debug.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import uvicorn
from fastapi import FastAPI
from view import page,api
from core.utils import Common
from fastapi.staticfiles import StaticFiles
import requests
import webbrowser
from loguru import logger
from view import page,api
from core.utils import Common
from core.engine import EngineServie

app = FastAPI(debug=True)
app.include_router(page.router)
Expand All @@ -25,8 +27,15 @@ def open_url(host: str, port: int) -> None:
flag = status(host, port)
webbrowser.open('http://{}:{}/plan'.format(host, port), new=2)

def main(host=Common.ip(), port=6006) -> None:
start(host, port)
def main(host=Common.ip(), port=6006, jmeter_server='off') -> None:
if jmeter_server == 'off':
start(host, port)
elif jmeter_server == 'on':
EngineServie.check_JavaEnvironment()
EngineServie.check_JmeterEnvironment()
Common.exec_cmd(f'{EngineServie.JMETER_SERVER_PATH.get(Common.pc_platform())} -Djava.rmi.server.hostname={host}')
else:
logger.error('The value of jmeter_server is invalid.')

if __name__ == "__main__":
main()
12 changes: 6 additions & 6 deletions webmeter/view/api.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from loguru import logger
from typing import Union
from fastapi import APIRouter, UploadFile, File, Form
from core.plan import TestPlan
from core.engine import EngineServie
from core.sqlhandle import crud, models, schemas
from core.sqlhandle.database import engine
from core.task import TaskDetail
from core.utils import Performance
from webmeter.core.plan import TestPlan
from webmeter.core.engine import EngineServie
from webmeter.core.sqlhandle import crud, models, schemas
from webmeter.core.sqlhandle.database import engine
from webmeter.core.task import TaskDetail
from webmeter.core.utils import Performance
router = APIRouter()
test_plan = TestPlan()
models.Base.metadata.create_all(bind=engine)
Expand Down
2 changes: 1 addition & 1 deletion webmeter/view/page.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from fastapi.responses import RedirectResponse
from fastapi import APIRouter
import os
from core.utils import Common
from webmeter.core.utils import Common

router = APIRouter()

Expand Down
21 changes: 15 additions & 6 deletions webmeter/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
import webbrowser
import multiprocessing
from fastapi.staticfiles import StaticFiles
from loguru import logger
from webmeter.view import page,api
from webmeter.core.utils import Common
from webmeter.core.engine import EngineServie

app = FastAPI(debug=False)
app.include_router(page.router)
Expand All @@ -29,9 +31,16 @@ def open_url(host: str, port: int) -> None:
flag = status(host, port)
webbrowser.open('http://{}:{}/plan'.format(host, port), new=2)

def main(host=Common.ip(), port=6006) -> None:
pool = multiprocessing.Pool(processes=2)
pool.apply_async(start, (host, port))
pool.apply_async(open_url, (host, port))
pool.close()
pool.join()
def main(host=Common.ip(), port=6006, jmeter_server='off') -> None:
if jmeter_server == 'off':
pool = multiprocessing.Pool(processes=2)
pool.apply_async(start, (host, port))
pool.apply_async(open_url, (host, port))
pool.close()
pool.join()
elif jmeter_server == 'on':
EngineServie.check_JavaEnvironment()
EngineServie.check_JmeterEnvironment()
Common.exec_cmd(f'{EngineServie.JMETER_SERVER_PATH.get(Common.pc_platform())} -Djava.rmi.server.hostname={host}')
else:
logger.error('The value of jmeter_server is invalid.')

0 comments on commit cb84da6

Please sign in to comment.