From d68ada5a565fb40a35c3734d738e98e957539ad8 Mon Sep 17 00:00:00 2001 From: Jeff Pihach Date: Thu, 23 Jul 2020 14:23:42 -0600 Subject: [PATCH 1/4] split controller connection and poller out into its own function. --- src/app/model-poller.js | 105 ++++++++++++++++++++-------------------- 1 file changed, 53 insertions(+), 52 deletions(-) diff --git a/src/app/model-poller.js b/src/app/model-poller.js index 7b48cfe3d..10f77028e 100644 --- a/src/app/model-poller.js +++ b/src/app/model-poller.js @@ -39,58 +39,9 @@ export default async function connectAndListModels( if (additionalControllers) { controllerList = controllerList.concat(additionalControllers); } - controllerList.forEach(async (controllerData) => { - let conn, error, juju, intervalId; - try { - ({ conn, error, juju, intervalId } = await loginWithBakery( - ...controllerData - )); - if (error) { - reduxStore.dispatch(storeLoginError(error)); - return; - } - } catch (e) { - return console.log("unable to log into controller", e, controllerData); - } - - // XXX Now that we can register multiple controllers this needs - // to be set per controller. - if (process.env.NODE_ENV === "production") { - Sentry.setTag("jujuVersion", conn?.info?.serverVersion); - } - - reduxStore.dispatch(updateControllerConnection(controllerData[0], conn)); - reduxStore.dispatch(updateJujuAPIInstance(controllerData[0], juju)); - reduxStore.dispatch( - updatePingerIntervalId(controllerData[0], intervalId) - ); - - fetchControllerList( - controllerData[0], - conn, - controllerData[4], - reduxStore - ); - // XXX the isJuju Check needs to be done on a per-controller basis - if (!isJuju) { - // This call will be a noop if the user isn't an administrator - // on the JIMM controller we're connected to. - disableControllerUUIDMasking(conn); - } - - do { - await reduxStore.dispatch(fetchModelList(conn), { - wsControllerURL: controllerData[0], - }); - await fetchAllModelStatuses(controllerData[0], conn, reduxStore); - // Wait 30s then start again. - await new Promise((resolve) => { - setTimeout(() => { - resolve(true); - }, 30000); - }); - } while (isLoggedIn(controllerData[0], reduxStore.getState())); - }); + controllerList.forEach((controllerData) => + connectAndPollController(controllerData, isJuju, reduxStore) + ); } catch (error) { // XXX Surface error to UI. // XXX Send to sentry if it's an error that's not connection related @@ -99,3 +50,53 @@ export default async function connectAndListModels( console.error("Something went wrong: ", error); } } + +export async function connectAndPollController( + controllerData, + isJuju, + reduxStore +) { + let conn, error, juju, intervalId; + try { + ({ conn, error, juju, intervalId } = await loginWithBakery( + ...controllerData + )); + if (error) { + reduxStore.dispatch(storeLoginError(error)); + return; + } + } catch (e) { + return console.log("unable to log into controller", e, controllerData); + } + + // XXX Now that we can register multiple controllers this needs + // to be sent per controller. + if (process.env.NODE_ENV === "production") { + Sentry.setTag("jujuVersion", conn?.info?.serverVersion); + } + + reduxStore.dispatch(updateControllerConnection(controllerData[0], conn)); + reduxStore.dispatch(updateJujuAPIInstance(controllerData[0], juju)); + reduxStore.dispatch(updatePingerIntervalId(controllerData[0], intervalId)); + + fetchControllerList(controllerData[0], conn, controllerData[4], reduxStore); + // XXX the isJuju Check needs to be done on a per-controller basis + if (!isJuju) { + // This call will be a noop if the user isn't an administrator + // on the JIMM controller we're connected to. + disableControllerUUIDMasking(conn); + } + + do { + await reduxStore.dispatch(fetchModelList(conn), { + wsControllerURL: controllerData[0], + }); + await fetchAllModelStatuses(controllerData[0], conn, reduxStore); + // Wait 30s then start again. + await new Promise((resolve) => { + setTimeout(() => { + resolve(true); + }, 30000); + }); + } while (isLoggedIn(controllerData[0], reduxStore.getState())); +} From dc163f4c00e196c65d9e0434a2a856ad3b02a38e Mon Sep 17 00:00:00 2001 From: Jeff Pihach Date: Fri, 24 Jul 2020 12:23:49 -0600 Subject: [PATCH 2/4] modify required attr to silence react warnings. --- src/pages/Controllers/Controllers.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/pages/Controllers/Controllers.js b/src/pages/Controllers/Controllers.js index 1d220b754..11ddc92d2 100644 --- a/src/pages/Controllers/Controllers.js +++ b/src/pages/Controllers/Controllers.js @@ -218,7 +218,7 @@ function RegisterAController({ onClose }) { id="full-name-stacked" name="controllerName" onChange={handleInputChange} - required="true" + required={true} />

Must be a valid alpha-numeric Juju controller name.
@@ -245,7 +245,7 @@ function RegisterAController({ onClose }) { id="full-name-stacked" name="wsControllerHost" onChange={handleInputChange} - required="true" + required={true} />

You'll typically want to use the public IP:Port address for the @@ -270,7 +270,6 @@ function RegisterAController({ onClose }) { id="full-name-stacked" name="username" onChange={handleInputChange} - required="" />

The username you use to access the controller. @@ -293,7 +292,6 @@ function RegisterAController({ onClose }) { id="full-name-stacked" name="password" onChange={handleInputChange} - required="" />

The password will be what you used when running{" "} @@ -316,7 +314,6 @@ function RegisterAController({ onClose }) { name="identityProvider" defaultChecked={false} onChange={handleInputChange} - required="" />