Skip to content

Commit

Permalink
Pull request update/240410
Browse files Browse the repository at this point in the history
bf4c852 OS-7473. Extracting live_demo.json on pod start
d8d9b9b OS-7443. [TS] Cover Greeter component with types
493b160 OS-7450. [TS - KeyValueLabel] Typing improvements and error
fixes
2229069 OS-7472. Fixed layout cleaner
  • Loading branch information
stanfra authored Apr 10, 2024
2 parents d720a82 + bf4c852 commit 14840c8
Show file tree
Hide file tree
Showing 13 changed files with 63 additions and 65 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test_layout_cleaner.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ jobs:
- name: Build image
run: bash -x build.sh layout_cleaner build
- name: Build test image and run tests
run: bash -x docker_images/layout_cleaner/run_test.sh
run: bash -x docker_images/run_test.sh layout_cleaner
19 changes: 0 additions & 19 deletions docker_images/layout_cleaner/run_test.sh

This file was deleted.

2 changes: 0 additions & 2 deletions docker_images/layout_cleaner/test-requirements.txt

This file was deleted.

10 changes: 5 additions & 5 deletions docker_images/layout_cleaner/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ def rest_cl(self):
return self._rest_cl

@staticmethod
def is_outdated(layout, employees_ids, applications_ids):
def is_outdated(layout, employees_ids, tasks_ids):
if (layout['owner_id'] not in employees_ids or (
layout['type'] == 'ml_run_charts_dashboard' and
layout['entity_id'] not in applications_ids)):
layout['entity_id'] not in tasks_ids)):
return True
return False

Expand All @@ -42,13 +42,13 @@ def clean_layouts(self):
organizations_ids = [x['id'] for x in organizations['organizations']]
for organization_id in organizations_ids:
LOG.info('Start processing for organization %s', organization_id)
_, applications = self.rest_cl.application_list(organization_id)
applications_ids = [x['id'] for x in applications['applications']]
_, tasks = self.rest_cl.task_list(organization_id)
tasks_ids = [x['id'] for x in tasks['tasks']]
_, employees = self.rest_cl.employee_list(organization_id)
employees_ids = [x['id'] for x in employees['employees']]
_, layouts = self.rest_cl.layouts_list(organization_id)
for layout in layouts['layouts']:
if self.is_outdated(layout, employees_ids, applications_ids):
if self.is_outdated(layout, employees_ids, tasks_ids):
LOG.info('Deleting layout %s', layout['id'])
self.rest_cl.layout_delete(organization_id, layout['id'])
LOG.info('Processing completed')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ const DetailsSummaryList = ({
key="reason"
keyMessageId="reason"
value={lastStatusError}
style={{
sx={{
maxWidth: "600px"
}}
/>
Expand Down
24 changes: 20 additions & 4 deletions ngui/ui/src/components/Greeter/Greeter.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ReactNode } from "react";
import LanguageOutlinedIcon from "@mui/icons-material/LanguageOutlined";
import Grid from "@mui/material/Grid";
import Link from "@mui/material/Link";
Expand All @@ -21,8 +22,18 @@ import { useIsDownMediaQuery, useIsUpMediaQuery } from "hooks/useMediaQueries";
import { HYSTAX, LIVE_DEMO } from "urls";
import { tag as tagHotjar } from "utils/hotjar";
import { SPACING_4, SPACING_2, SPACING_6 } from "utils/layouts";
import { isEven } from "utils/math";
import useStyles from "./Greeter.styles";

type LiveDemoButtonProps = {
onClick: () => void;
};

type GreeterProps = {
form: ReactNode;
oAuthForm: ReactNode;
};

const OptScaleLink = () => {
const { classes, cx } = useStyles();
const intl = useIntl();
Expand Down Expand Up @@ -82,7 +93,7 @@ const ImagesWithCaptions = () => {
);
};

const LiveDemoButton = ({ onClick }) => (
const LiveDemoButton = ({ onClick }: LiveDemoButtonProps) => (
<Button
dataTestId="btn_live_demo"
color="lightYellow"
Expand All @@ -93,17 +104,22 @@ const LiveDemoButton = ({ onClick }) => (
/>
);

const defaultOrder = [0, 1, 2, 3, 4, 5];
const defaultOrder = [0, 1, 2, 3, 4, 5] as const;

const getVerticalOrder = () => {
const [evenNumbers, oddNumbers] = defaultOrder.reduce(
([even, odd], curr) => (curr % 2 === 0 ? [[...even, curr], [...odd]] : [[...even], [...odd, curr]]),
([even, odd]: [number[], number[]], curr) => {
if (isEven(curr)) {
return [[...even, curr], [...odd]];
}
return [[...even], [...odd, curr]];
},
[[], []]
);
return [...evenNumbers, ...oddNumbers];
};

const Greeter = ({ form, oAuthForm }) => {
const Greeter = ({ form, oAuthForm }: GreeterProps) => {
const { classes, cx } = useStyles();
const theme = useTheme();
const navigate = useNavigate();
Expand Down
16 changes: 12 additions & 4 deletions ngui/ui/src/components/KeyValueLabel/KeyValueLabel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,19 @@ import { Box } from "@mui/material";
import Typography, { TypographyOwnProps } from "@mui/material/Typography";
import { FormattedMessage } from "react-intl";

type KeyValueLabelProps = {
type KeyType =
| {
keyMessageId: string;
keyText?: never;
}
| {
keyMessageId?: never;
keyText: string;
};

type KeyValueLabelProps = KeyType & {
value: ReactNode;
variant: TypographyOwnProps["variant"];
keyMessageId?: string;
keyText?: string;
variant?: TypographyOwnProps["variant"];
isBoldValue?: boolean;
dataTestIds?: {
typography?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import KeyValueLabel from "components/KeyValueLabel/KeyValueLabel";
const RightsizingFlavorCell = ({ flavorName, flavorCpu }) => (
<CaptionedCell
caption={{
node: <KeyValueLabel keyMessageId="cpu" value={flavorCpu} isBoldValue={false} typographyProps={{ variant: "caption" }} />
node: <KeyValueLabel keyMessageId="cpu" value={flavorCpu} isBoldValue={false} variant="caption" />
}}
>
{flavorName}
Expand Down
4 changes: 2 additions & 2 deletions ngui/ui/src/components/UpcomingBooking/UpcomingBooking.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ const UpcomingBooking = ({ employeeName, acquiredSince, releasedAt }) => {
return (
<>
<KeyValueLabel keyMessageId="user" value={employeeName} />
<KeyValueLabel keyMessageId="since" valueWhiteSpace="nowrap" value={bookedSince} />
<KeyValueLabel keyMessageId="until" valueWhiteSpace="nowrap" value={bookedUntil} />
<KeyValueLabel keyMessageId="since" value={bookedSince} />
<KeyValueLabel keyMessageId="until" value={bookedUntil} />
<BookingTimeMeasure messageId="duration" measure={duration} />
</>
);
Expand Down
16 changes: 4 additions & 12 deletions ngui/ui/src/stories/Components/KeyValueLabel.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,12 @@ import KeyValueLabel from "components/KeyValueLabel";
export default {
component: KeyValueLabel,
argTypes: {
separator: {
name: "Separator",
control: "select",
options: ["colon", "hyphen"],
defaultValue: "colon"
},
messageId: { name: "Message ID", control: "text", defaultValue: "name" },
text: { name: "Text", control: "text", defaultValue: "" },
keyMessageId: { name: "Key message id", control: "text", defaultValue: "name" },
keyText: { name: "Key text", control: "text", defaultValue: "" },
value: { name: "Value", control: "text", defaultValue: "value" }
}
};

export const basic = () => <KeyValueLabel messageId="name" value="value" />;
export const basic = () => <KeyValueLabel keyMessageId="name" value="value" />;

export const withKnobs = (args) => (
<KeyValueLabel messageId={args.messageId} text={args.text} value={args.value} separator={args.separator} />
);
export const withKnobs = (args) => <KeyValueLabel keyMessageId={args.keyMessageId} keyText={args.keyText} value={args.value} />;
2 changes: 2 additions & 0 deletions ngui/ui/src/utils/math.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,5 @@ export const denormalize = (normalizedValue, domain, range) => {

return denormalized;
};

export const isEven = (value: number) => value % 2 === 0;
18 changes: 4 additions & 14 deletions rest_api/rest_api_server/controllers/live_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import logging
import os
import uuid
import tarfile
from collections import defaultdict
from json.decoder import JSONDecodeError
from kombu.pools import producers
Expand Down Expand Up @@ -45,7 +44,6 @@
DEMO_USER_NAME = 'Demo User'
EMAIL_TEMPLATE = '%[email protected]'
PRESET_FILENAME = 'rest_api/live_demo.json'
PRESET_TAR_XZ = 'rest_api/live_demo.tar.xz'
DUPLICATION_MODULE_NAMES = {'abandoned_instances', 'rightsizing_instances'}
DUPLICATION_COUNT = 3
TOP_NO_DUPLICATE_RESOURCES = 10
Expand Down Expand Up @@ -361,21 +359,13 @@ def _get_basic_params():
return org, name, email, passwd

@staticmethod
def load_preset(path=None, tar_path=None):
if not os.path.exists(path) and not os.path.exists(tar_path):
raise InternalServerError(Err.OE0452, [])
def load_preset(path=None):
if not os.path.exists(path):
try:
with tarfile.open(tar_path, 'r:xz') as f:
f.extract(
os.path.basename(PRESET_FILENAME),
path=os.path.dirname(PRESET_FILENAME))
except FileNotFoundError:
raise InternalServerError(Err.OE0452, [])
raise InternalServerError(Err.OE0452, [])
try:
with open(path, 'r') as f:
return json.load(f)
except (JSONDecodeError, FileNotFoundError):
except JSONDecodeError:
raise InternalServerError(Err.OE0450, [])

def duplicate_resource(self, preset_object, duplication_resource_info_map):
Expand Down Expand Up @@ -1368,7 +1358,7 @@ def _create(self, pregenerate=False):
self.session, self._config, self.token
).get_or_create_profiling_token(organization.id)

preset = self.load_preset(PRESET_FILENAME, PRESET_TAR_XZ)
preset = self.load_preset(PRESET_FILENAME)
employee_id_to_replace = self.get_replacement_employee(preset)
self.init_duplication_resources(preset)
try:
Expand Down
11 changes: 11 additions & 0 deletions rest_api/rest_api_server/server.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import logging
import argparse
import tarfile
import tornado.ioloop
import pydevd_pycharm
from etcd import Lock as EtcdLock
Expand Down Expand Up @@ -29,6 +30,9 @@
BASE_URL_PREFIX = "/restapi"
URL_PREFIX_v2 = "/restapi/v2"

PRESET_FILENAME = 'rest_api/live_demo.json'
PRESET_TAR_XZ = 'rest_api/live_demo.tar.xz'


def get_handlers(handler_kwargs, version=None):
result = []
Expand Down Expand Up @@ -584,6 +588,13 @@ def main():
args = parser.parse_args()

app = make_app(DBType.MySQL, args.etcdhost, args.etcdport, wait=True)
try:
with tarfile.open(PRESET_TAR_XZ, 'r:xz') as f:
f.extract(
os.path.basename(PRESET_FILENAME),
path=os.path.dirname(PRESET_FILENAME))
except Exception as exc:
LOG.exception(exc)
LOG.info("start listening on port %d", DEFAULT_PORT)
app.listen(DEFAULT_PORT, decompress_request=True)
tornado.ioloop.IOLoop.instance().start()
Expand Down

0 comments on commit 14840c8

Please sign in to comment.