-
Notifications
You must be signed in to change notification settings - Fork 0
Mb submit in lib #3
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| DEBUG_FLAG=True |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,14 +7,15 @@ | |
| from rest_framework.decorators import api_view, permission_classes, authentication_classes | ||
| from rest_framework.permissions import IsAuthenticated, AllowAny | ||
| from .models import LibraryRegistration | ||
| from webcligui_api import ParameterList, ParameterOptionsToList, ParameterPreference, ParameterStringValue | ||
| # from webcligui_api import ParameterList, ParameterOptionsToList, ParameterPreference, ParameterStringValue | ||
|
|
||
| libraryApis = [] | ||
| library2Idx = {} | ||
|
|
||
| def instantiateLibraryModule(obj): | ||
| module = importlib.import_module(obj.module_path) | ||
| cls = getattr(module, obj.class_name) | ||
| print(f"api.py-- cls={cls} obj={obj} class_name={obj.class_name} module={module} ") | ||
| libraryAPIImpl = cls() | ||
| return libraryAPIImpl | ||
|
|
||
|
|
@@ -24,9 +25,11 @@ def load_library_apis(): | |
| return | ||
|
|
||
| for idx, obj in enumerate(LibraryRegistration.objects.all()): | ||
| print(f"api.py-- idx={idx} obj={obj} name={obj.library_name} module={obj.module_path} ") | ||
| libraryAPIImpl = instantiateLibraryModule(obj) | ||
| libraryApis.append(libraryAPIImpl) | ||
| library2Idx[obj.library_name] = idx | ||
| # library2Idx[obj.module_path] = idx | ||
|
|
||
| def to_json_safe(obj): | ||
| if isinstance(obj, Enum): | ||
|
|
@@ -69,7 +72,7 @@ def get_description(request): | |
| libraryApiImpl = getLibraryApi(libraryName) | ||
| if not libraryApiImpl: | ||
| errMsg = f'Libraryname "{libraryName}" not known!' | ||
| print('get_description():', errMsg) | ||
| print('api.py--get_description():', errMsg) | ||
| return HttpResponseBadRequest(errMsg) | ||
|
|
||
| operationBranch = body["operationBranch"][1:] | ||
|
|
@@ -84,9 +87,10 @@ def get_parameters(request): | |
| body = json.loads(request.body) | ||
| libraryName = body["operationBranch"][0] | ||
| libraryApiImpl = getLibraryApi(libraryName) | ||
| print(f"api.py--get_parameters(): libraryName={libraryName}") | ||
| if not libraryApiImpl: | ||
| errMsg = f'Libraryname "{libraryName}" not known!' | ||
| print('get_parameters():', errMsg) | ||
| print('api.py--get_parameters():', errMsg) | ||
| return HttpResponseBadRequest(errMsg) | ||
|
|
||
| operationBranch = body["operationBranch"][1:] | ||
|
|
@@ -100,16 +104,20 @@ def get_parameters(request): | |
| @permission_classes([AllowAny]) | ||
| def submit_operation(request): | ||
| body = json.loads(request.body) | ||
| libraryName = body["operationBranch"][0] | ||
| libraryApiImpl = getLibraryApi(libraryName) | ||
| if not libraryApiImpl: | ||
| errMsg = f'Libraryname "{libraryName}" not known!' | ||
| print('api.py--submit_operation():', errMsg) | ||
| return HttpResponseBadRequest(errMsg) | ||
|
|
||
| operationBranch = body["operationBranch"][1:] | ||
| command = body['command'] | ||
| servers = body["servers"] | ||
|
|
||
| print(f"api.py--submit_operation(): libraryName={libraryName}, operationBranch={operationBranch}") | ||
| print(f"command={command}, servers={servers}") | ||
|
|
||
| result = libraryApiImpl.submitOperation(body['operationBranch'], command, servers) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm sorry, but I don't see the use of this function being called in the libraryApi. The libraryApi is purely meant to pass in the different operations to webCliGui. When the operation is selected it should just run in our server. I don't know what you need to do to actually run the operation (can't it just run in Django since it is fully operational in bisos?). However, if there is some reason that you need to run it in your environment then I would like to run it in a separate library that you created. Not in the libraryApi. The reason why I don't want it is that we are going to provide the service to T-Mobile. Therefore we need to be fully responsible for running the operation, not T-Mobile themselves. Giving a library to them so they could call it would defeat that purpose and would make our work counterproductive. We need to call that library ourselves. |
||
|
|
||
| print('command:', command, 'servers:', servers) | ||
| fullCommand = command + ['localhost'] | ||
| print('fullCommand:', fullCommand) | ||
| try: | ||
| subprocess.run(fullCommand, check=True) | ||
| except Exception as exc: | ||
| print('Exception:', exc) | ||
| return HttpResponseServerError(str(exc)); | ||
|
|
||
| return HttpResponse('OK') | ||
| return JsonResponse(result, safe=False) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,7 +11,11 @@ import Button from "./Button"; | |
| import { FetchState } from "../utils/fetchData"; | ||
| import WaitCircle from "./WaitCircle"; | ||
|
|
||
| const CreationSteps = () => { | ||
| interface CreationStepsProps { | ||
| operationPos: string | null; | ||
| } | ||
|
|
||
| const CreationSteps = ({ operationPos }: CreationStepsProps) => { | ||
| const { | ||
| taskCreationStep, | ||
| isNextStepValid, | ||
|
|
@@ -23,7 +27,9 @@ const CreationSteps = () => { | |
| if (taskCreationStep !== TaskCreationSteps.Preview) { | ||
| setNextTaskCreationStep(taskCreationStep + 1); | ||
| } else { | ||
| submitOperation(); | ||
| if (operationPos) { | ||
| submitOperation(operationPos); | ||
| } | ||
| } | ||
| }; | ||
|
|
||
|
|
@@ -66,9 +72,10 @@ const CreationSteps = () => { | |
|
|
||
| interface OperationSelectionProps { | ||
| isVisible: boolean; | ||
| onSelectOperation: (pos: string) => void; | ||
| } | ||
|
|
||
| const OperationSelection = ({ isVisible }: OperationSelectionProps) => { | ||
| const OperationSelection = ({ isVisible, onSelectOperation }: OperationSelectionProps) => { | ||
| const { | ||
| taskTrees, | ||
| selectedOperationBranch, | ||
|
|
@@ -78,7 +85,9 @@ const OperationSelection = ({ isVisible }: OperationSelectionProps) => { | |
| } = useDataStore(state => state.createTask); | ||
|
|
||
| const onSelect = (selectedKeys: React.Key[], selectData: any) => { | ||
| setSelectedOperation(selectData.node.pos); | ||
| const pos = selectData.node.pos; | ||
| onSelectOperation(pos); | ||
| setSelectedOperation(pos); | ||
| }; | ||
|
|
||
| let selectedOperation: Operation | null = null; | ||
|
|
@@ -362,12 +371,17 @@ const Preview = ({ | |
| ); | ||
| }; | ||
|
|
||
| const CreationViews = () => { | ||
| interface CreationViewsProps { | ||
| operationPos: string | null; | ||
| setOperationPos: (pos: string) => void; | ||
| } | ||
|
|
||
| const CreationViews = ({ operationPos, setOperationPos }: CreationViewsProps) => { | ||
| const { taskCreationStep } = useDataStore(state => state.createTask); | ||
|
|
||
| return ( | ||
| <> | ||
| <OperationSelection isVisible={taskCreationStep === TaskCreationSteps.OperatorSelection} /> | ||
| <OperationSelection isVisible={taskCreationStep === TaskCreationSteps.OperatorSelection} onSelectOperation={setOperationPos} /> | ||
| <OperationParameters isVisible={taskCreationStep === TaskCreationSteps.Parameters} /> | ||
| <SelectServers isVisible={taskCreationStep === TaskCreationSteps.ServersSelection} /> | ||
| <Preview isVisible={taskCreationStep === TaskCreationSteps.Preview} /> | ||
|
|
@@ -376,16 +390,17 @@ const CreationViews = () => { | |
| }; | ||
|
|
||
| const CreateTask = () => { | ||
| const { getLibraryOperators } = useDataStore(state => state.createTask); | ||
| const { getLibraryOperators } = useDataStore(state => state.createTask); | ||
| const [operationPos, setOperationPos] = React.useState<string | null>(null); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a no-no: the useState is never used. All the data is stored in the dataStore so the useState is of no use (except for small local variables like the tabs - these are not stored in the datastore). You can see it in CreateViews where the selected operation is stored in the dataStore using setSelectedOperation. Please remove this and all references to it. |
||
|
|
||
| useEffect(() => { | ||
| getLibraryOperators(); | ||
| }, []); | ||
|
|
||
| return ( | ||
| <div className="flex flex-col"> | ||
| <CreationSteps /> | ||
| <CreationViews /> | ||
| <CreationSteps operationPos={operationPos} /> | ||
| <CreationViews operationPos={operationPos} setOperationPos={setOperationPos} /> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,5 +35,5 @@ export interface CreateTaskIf { | |
| loadParameters: () => Promise<FetchStatus>; | ||
| setParameterValue: (parameterBranch: number[], value: ParameterValue) => void; | ||
| getExecuteCommand: () => string[] | null; | ||
| submitOperation: () => void; | ||
| submitOperation: (operationPos: string) => Promise<FetchStatus>; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The operationPos is already in the dataStore in createTask.selectedOperationBranch. Please remove this parameter operationPos. |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -425,9 +425,14 @@ const doGetExecuteCommand = (get: GetFunction) => { | |
| return [operation.name, ...params]; | ||
| } | ||
|
|
||
| const doSubmitOperation = async (get: GetFunction, set: SetFunction) => { | ||
| const doSubmitOperation = async (operationPos: string, get: GetFunction, set: SetFunction) => { | ||
| const cmd = doGetExecuteCommand(get) as string[]; | ||
|
|
||
| const operationBranch = getOperationBranch(operationPos, get().createTask.taskTrees); | ||
| if (!operationBranch) { | ||
| return FetchState.Idle; | ||
| } | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The operationBranch is available already in the dataStore. Please get it with get().createTask.selectedOperationBranch. You don't need to pass in operationPos. |
||
| const setFetchStatus = (stat: FetchStatus) => | ||
| set(state => { state.createTask.submitOperationFetchAndError.fetchStatus = stat; }, | ||
| false, 'submitOperationFetchStatus'); | ||
|
|
@@ -439,14 +444,15 @@ const doSubmitOperation = async (get: GetFunction, set: SetFunction) => { | |
| }, false, 'submitOperationError'); | ||
|
|
||
| interface SubmitOperation { | ||
| operationBranch: string[]; | ||
| command: string[]; | ||
| servers: string[]; | ||
| } | ||
|
|
||
| return await fetchData<string, SubmitOperation>( | ||
| '/api/submit-operation', | ||
| { | ||
| postData: { command: cmd, servers: [WEB_CLI_GUI_SERVER] }, | ||
| postData: { operationBranch: operationBranch, command: cmd, servers: [WEB_CLI_GUI_SERVER] }, | ||
| setFetchStatus, | ||
| setError, | ||
| } | ||
|
|
@@ -489,7 +495,7 @@ export const useDataStore = create<DataStoreIf>()( | |
| loadParameters: async () => await doLoadParameters(get, set), | ||
| setParameterValue: (parameterBranch: number[], value: ParameterValue) => doSetParameterValue(parameterBranch, value, get, set), | ||
| getExecuteCommand: () => doGetExecuteCommand(get), | ||
| submitOperation: () => doSubmitOperation(get, set), | ||
| submitOperation: (operationPos: string) => doSubmitOperation(operationPos, get, set), | ||
| } | ||
| })), { | ||
| name: 'DataStore', | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,3 +16,7 @@ def getDescription(self, operationBranch: list[str]) -> str: | |
| @abstractmethod | ||
| def getParameters(self, operationBranch: list[str]) -> ParameterData: | ||
| pass | ||
|
|
||
| @abstractmethod | ||
| def submitOperation(self, operationBranch: list[str], command: list[str], servers: list[str]): | ||
| pass | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See my comment above in api.py. This method is counterproductive. |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since it is commented out why don't we remove this line?