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

Powerarena 1.3.0 #2

Merged
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
166 changes: 166 additions & 0 deletions PaDockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

######################################################################
# PY stage that simply does a pip install on our requirements
######################################################################
ARG PY_VER=3.7.9
FROM python:${PY_VER} AS superset-py

RUN mkdir /app \
&& apt-get update -y \
&& apt-get install -y --no-install-recommends \
build-essential \
default-libmysqlclient-dev \
libpq-dev \
libsasl2-dev \
libecpg-dev \
&& rm -rf /var/lib/apt/lists/*

# First, we just wanna install requirements, which will allow us to utilize the cache
# in order to only build if and only if requirements change
COPY ./requirements/*.txt /app/requirements/
COPY setup.py MANIFEST.in README.md /app/
COPY superset-frontend/package.json /app/superset-frontend/
RUN cd /app \
&& mkdir -p superset/static \
&& touch superset/static/version_info.json \
&& pip install --no-cache -r requirements/local.txt


######################################################################
# Node stage to deal with static asset construction
######################################################################
FROM node:14 AS superset-node

ARG NPM_VER=7
RUN npm install -g npm@${NPM_VER}

ARG NPM_BUILD_CMD="build"
ENV BUILD_CMD=${NPM_BUILD_CMD}

# NPM ci first, as to NOT invalidate previous steps except for when package.json changes
RUN mkdir -p /app/superset-frontend
RUN mkdir -p /app/superset/assets
COPY ./docker/frontend-mem-nag.sh /
COPY ./superset-frontend/package* /app/superset-frontend/
RUN /frontend-mem-nag.sh \
&& cd /app/superset-frontend \
&& npm ci

# Next, copy in the rest and let webpack do its thing
COPY ./superset-frontend /app/superset-frontend
# This is BY FAR the most expensive step (thanks Terser!)
RUN cd /app/superset-frontend \
&& npm run ${BUILD_CMD} \
&& rm -rf node_modules


######################################################################
# Final lean image...
######################################################################
ARG PY_VER=3.7.9
FROM python:${PY_VER} AS lean

ENV LANG=C.UTF-8 \
LC_ALL=C.UTF-8 \
FLASK_ENV=production \
FLASK_APP="superset.app:create_app()" \
PYTHONPATH="/app/pythonpath" \
SUPERSET_HOME="/app/superset_home" \
SUPERSET_PORT=8088

RUN mkdir -p ${PYTHONPATH} \
&& useradd --user-group -d ${SUPERSET_HOME} -m --no-log-init --shell /bin/bash superset \
&& apt-get update -y \
&& apt-get install -y --no-install-recommends \
build-essential \
default-libmysqlclient-dev \
libsasl2-modules-gssapi-mit \
libpq-dev \
&& rm -rf /var/lib/apt/lists/*

COPY ./superset_config.py /app/pythonpath
COPY --from=superset-py /usr/local/lib/python3.7/site-packages/ /usr/local/lib/python3.7/site-packages/
# Copying site-packages doesn't move the CLIs, so let's copy them one by one
COPY --from=superset-py /usr/local/bin/gunicorn /usr/local/bin/celery /usr/local/bin/flask /usr/bin/
COPY --from=superset-node /app/superset/static/assets /app/superset/static/assets
COPY --from=superset-node /app/superset-frontend /app/superset-frontend

## Lastly, let's install superset itself
COPY superset /app/superset
COPY setup.py MANIFEST.in README.md /app/
RUN cd /app \
&& chown -R superset:superset * \
&& pip install -e .

COPY ./docker/docker-entrypoint.sh /usr/bin/

WORKDIR /app

USER superset

HEALTHCHECK CMD curl -f "http://localhost:$SUPERSET_PORT/health"

EXPOSE ${SUPERSET_PORT}

ENTRYPOINT ["/usr/bin/docker-entrypoint.sh"]

######################################################################
# Dev image...
######################################################################
# FROM lean AS dev
# ARG GECKODRIVER_VERSION=v0.28.0
# ARG FIREFOX_VERSION=88.0

# COPY ./requirements/*.txt ./docker/requirements-*.txt/ /app/requirements/

# USER root

# RUN apt-get update -y \
# && apt-get install -y --no-install-recommends libnss3 libdbus-glib-1-2 libgtk-3-0 libx11-xcb1

# # Install GeckoDriver WebDriver
# RUN wget https://github.com/mozilla/geckodriver/releases/download/${GECKODRIVER_VERSION}/geckodriver-${GECKODRIVER_VERSION}-linux64.tar.gz -O /tmp/geckodriver.tar.gz && \
# tar xvfz /tmp/geckodriver.tar.gz -C /tmp && \
# mv /tmp/geckodriver /usr/local/bin/geckodriver && \
# rm /tmp/geckodriver.tar.gz

# # Install Firefox
# RUN wget https://download-installer.cdn.mozilla.net/pub/firefox/releases/${FIREFOX_VERSION}/linux-x86_64/en-US/firefox-${FIREFOX_VERSION}.tar.bz2 -O /opt/firefox.tar.bz2 && \
# tar xvf /opt/firefox.tar.bz2 -C /opt && \
# ln -s /opt/firefox/firefox /usr/local/bin/firefox

# # Cache everything for dev purposes...
# RUN cd /app \
# && pip install --no-cache -r requirements/docker.txt \
# && pip install --no-cache -r requirements/requirements-local.txt || true
# USER superset


# ######################################################################
# # CI image...
# ######################################################################
# FROM lean AS ci

# COPY --chown=superset ./docker/docker-bootstrap.sh /app/docker/
# COPY --chown=superset ./docker/docker-init.sh /app/docker/
# COPY --chown=superset ./docker/docker-ci.sh /app/docker/

# RUN chmod a+x /app/docker/*.sh

# CMD /app/docker/docker-ci.sh
4 changes: 3 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ x-superset-volumes: &superset-volumes
- ./superset-frontend:/app/superset-frontend
- superset_home:/app/superset_home
- ./tests:/app/tests
- /etc/timezone:/etc/timezone
- /etc/localtime:/etc/localtime

version: "3.7"
services:
Expand All @@ -44,7 +46,7 @@ services:
container_name: superset_db
restart: unless-stopped
ports:
- "127.0.0.1:5432:5432"
- "127.0.0.1:35432:5432"
volumes:
- db_home:/var/lib/postgresql/data

Expand Down
25 changes: 25 additions & 0 deletions superset-frontend/src/chart/chartAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,31 @@ export function postChartFormData(
* This will post the form data to the endpoint, returning a new chart.
*
*/

/*
* [MODIFY-TIMEZONE]
*/
if (!isNaN(Date.parse(formData['time_range'].split(" : ")[0]))) {
const since = Date.parse(formData['time_range'].split(" : ")[0]);
const until = Date.parse(formData['time_range'].split(" : ")[1]);
const utcSince = new Date(since).toISOString().split(".")[0];
const utcUntil = new Date(until).toISOString().split(".")[0];
formData['time_range'] = utcSince + " : " + utcUntil;
}
const mappings = {
"Last": {"index": 1, "day": 1, "week": 7, "month": 31, "quarter": 91, "year": 365},
"previous": {"index": 2, "week": 7, "month": 30, "year": 365}
}
if ("Last" === formData.time_range.split(" ")[0] || "previous" === formData.time_range.split(" ")[0]) {
let type = formData.time_range.split(" ")[0];
const utcSince = new Date(
Date.parse(new Date(Date.now()).toDateString())
- mappings[type][formData.time_range.split(" ")[mappings[type]["index"]]] * 24 * 3600 * 1000
).toISOString().split(".")[0];
const utcUntil = new Date(Date.parse(new Date(Date.now()).toDateString())).toISOString().split(".")[0];
formData['time_range'] = utcSince + " : " + utcUntil;
}

return exploreJSON(
formData,
force,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,20 @@ export default React.memo(
})}
>
{row.cells.map(cell => {
// console.log("@296", cell);
/*
* [MODIFY-TIMEZONE]
* have to change event ts to local timezone.
*/
try {
if (!isNaN(Date.parse(cell.value)) && ("P_EVENT_TS" === cell.column.Header || "event_ts" === cell.column.Header)) {
cell.value = new Date(Date.parse(cell.value.split(".")[0]) + 16 * 3600 * 1000).toISOString();
// console.log("@296-1", cell.value);
}
} catch {
// console.log("@296-2 not a date");
}
// console.log("@296-3", cell);
if (cell.column.hidden) return null;

const columnCellProps = cell.column.cellProps || {};
Expand All @@ -311,7 +325,9 @@ export default React.memo(
className={cx({ 'loading-bar': loading })}
role={loading ? 'progressbar' : undefined}
>
<span data-test="cell-text">{cell.render('Cell')}</span>
<span data-test="cell-text">{
cell.value
}</span>
</span>
</td>
);
Expand All @@ -325,12 +341,31 @@ export default React.memo(
);

let showRowData = (row: object) => {
let clientName = "msi";
// let clientName = process.env.CLIENT_NAME;
/*
* normally it will get clientName from superset-[clientName].standalone...
* if the domain is not superset..., you can set [clientName]-- at chart name head.
* Example: demo--[Workstations_Chart] clientName = demo.
*/
let clientName = "";
try {
clientName = window.location.href.split("superset-")[1].split(".standalone")[0] || "";
} catch {

}
if ("" === clientName) {
const chartName = $(".editable-title").children().attr('value');
clientName = chartName?.split("--")[0] || "";
}
let entityCode = row['original']['P_DEVICE_ID'];
let pos = row['original']['P_POS'];
let endTime = Date.parse(row['original']['P_EVENT_TS']);
let startTime = endTime - row['original']['P_VALUE'] * 1000;
if (undefined === entityCode) {
entityCode = row['original']['device_id'];
pos = row['original']['pos'];
endTime = row['original']['event_ts'];
startTime = endTime - row['original']['cycle_time'] * 1000
}
let url = 'https://manage-' + clientName + '.standalone.powerarena.com:10443/admin/mark-for-reason/?tab=single-view&entity_code=' + entityCode + '&pos=' + pos + '&start_ts=' + startTime + '&end_ts=' + endTime;
window.open(url, '_blank')?.focus();
}
14 changes: 11 additions & 3 deletions superset-frontend/src/explore/components/PaExploreChartPanel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ const Styles = styled.div`
`;

const ExploreChartPanel = props => {
console.log("@118 form_data", props.form_data)
const theme = useTheme();
const gutterMargin = theme.gridUnit * GUTTER_SIZE_FACTOR;
const gutterHeight = theme.gridUnit * GUTTER_SIZE_FACTOR;
Expand Down Expand Up @@ -268,7 +267,7 @@ const ExploreChartPanel = props => {
props.updateTableForm({
'value': [targetItem[0], targetItem[2]],
'type': 'P_VALUE',
'ops': ['>=', '<']
'ops': ['>', '<=']
}, props.chartName);
}
}
Expand All @@ -278,7 +277,6 @@ const ExploreChartPanel = props => {
$(".panel-body").unbind("click").click(
function (e) {
let target = $(".nvtooltip").children("div").children("table").children("thead").text();
console.log("@281", target);
props.updateTableForm({
'value': [target],
'type': ['P_EVENT_TS'],
Expand Down Expand Up @@ -311,6 +309,16 @@ const ExploreChartPanel = props => {
}, props.chartName)} >
{value.x}
</Button>
case props.chartName.includes('[Flatten_Workstations_Chart]'):
return <Button
class="clickButton"
onClick={() => props.updateTableForm({
'value': [[value.x]],
'type': ['workstation_name'],
'ops': ['IN']
}, props.chartName)} >
{value.x}
</Button>
default:
return <p></p>
}
Expand Down
Loading