Skip to content

Commit

Permalink
Merge pull request #251 from mtconnect/fix_cutting_tool_asset_element…
Browse files Browse the repository at this point in the history
…_order

Fixed oredr of cutter status in cutting items
  • Loading branch information
wsobel authored Jul 13, 2022
2 parents ee84d8c + b642087 commit 2dc0f67
Show file tree
Hide file tree
Showing 3 changed files with 182 additions and 1 deletion.
135 changes: 135 additions & 0 deletions Dockerfile.alpine
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
# MTConnect Public C++ Agent Docker image build instructions

# ---------------------------------------------------------------------
# notes
# ---------------------------------------------------------------------

# to build locally and push to docker hub, run this with something like -
#
# docker buildx build \
# --platform linux/amd64,linux/arm64 \
# --tag ladder99/agent2 \
# --secret id=access_token,src=ACCESS_TOKEN \
# --push \
# .
#
# then should be able to run with something like
#
# docker run -it -p5001:5000 --name agent2 --rm ladder99/agent2:latest
#
# and visit http://localhost:5001 to see demo output

# ---------------------------------------------------------------------
# os
# ---------------------------------------------------------------------

# base image - ubuntu has linux/amd64, linux/arm64 etc
FROM alpine:latest AS os

# tzinfo hangs without this
ARG DEBIAN_FRONTEND=noninteractive

# ---------------------------------------------------------------------
# build
# ---------------------------------------------------------------------

FROM os AS build

# update os and add dependencies
# this follows recommended Docker practices -
# see https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#run
# note: Dockerfiles run as root by default, so don't need sudo
RUN apk update \
&& apk add g++ python3 cmake git linux-headers make perl ruby \
&& gem install rake

RUN python3 -m ensurepip \
&& python3 -m pip install --upgrade pip \
&& python3 -m pip install conan

# get latest source code
# NOTE: make sure you are checking out the right repo - github.com/bburns OR github.com/mtconnect
# could use `git checkout foo` to get a specific version here
RUN --mount=type=secret,id=access_token \
cd ~ \
&& git clone --recurse-submodules --progress --depth 1 \
https://github.com/mtconnect/cppagent.git agent

# set some variables
ENV PATH=$HOME/venv3.9/bin:$PATH
ENV CONAN_PROFILE=conan/profiles/docker
ENV WITH_RUBY=True
ENV WITH_TESTS=False

# limit cpus so don't run out of memory on local machine
# symptom: get error - "c++: fatal error: Killed signal terminated program cc1plus"
# can turn off if building in cloud
ENV CONAN_CPU_COUNT=1

# make installer
RUN cd ~/agent \
&& conan export conan/mqtt_cpp \
&& conan export conan/mruby \
&& conan install . -if build --build=missing \
-pr $CONAN_PROFILE \
-o run_tests=$WITH_TESTS \
-o with_ruby=$WITH_RUBY

# compile source (~20mins - 4hrs for qemu)
RUN cd ~/agent && conan build . -bf build

# ---------------------------------------------------------------------
# release
# ---------------------------------------------------------------------

FROM os AS release

LABEL author="mtconnect" description="Docker image for the latest Production MTConnect C++ Agent"

# install ruby for simulator
RUN apk update && apk upgrade && apk add ruby

# change to a new non-root user for better security.
# this also adds the user to a group with the same name.
# --create-home creates a home folder, ie /home/<username>
RUN useradd --create-home agent
USER agent

# install agent executable
COPY --chown=agent:agent --from=build /root/agent/build/bin/agent /usr/local/bin/

# copy data to /etc/mtconnect
COPY --chown=agent:agent --from=build /root/agent/schemas /etc/mtconnect/schemas
COPY --chown=agent:agent --from=build /root/agent/simulator /etc/mtconnect/simulator
COPY --chown=agent:agent --from=build /root/agent/styles /etc/mtconnect/styles

# expose port
EXPOSE 5000

WORKDIR /home/agent
# WORKDIR /etc/mtconnect

# default command - can override with docker run or docker-compose command.
# this runs the adapter simulator and the agent using the sample config file.
# note: must use shell form here instead of exec form, since we're running
# multiple statements using shell commands (& and &&).
# see https://stackoverflow.com/questions/46797348/docker-cmd-exec-form-for-multiple-command-execution
CMD /usr/bin/ruby /etc/mtconnect/simulator/run_scenario.rb -l \
/etc/mtconnect/simulator/VMC-3Axis-Log.txt & \
cd /etc/mtconnect/simulator && agent run agent.cfg

# ---------------------------------------------------------------------
# note
# ---------------------------------------------------------------------

# after setup, the dirs look like this -
#
# /usr/local/bin
# |-- agent - the cppagent application
#
# /etc/mtconnect
# |-- schemas - xsd files
# |-- simulator - agent.cfg, simulator.rb, vmc-3axis.xml, log.txt
# |-- styles - styles.xsl, styles.css, favicon.ico, etc
#
# /home/agent - the user's directory
3 changes: 2 additions & 1 deletion src/asset/cutting_tool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ namespace mtconnect {
item->setAny(true);

measurements->registerMatchers();
item->setOrder({"Description", "Locus", "ItemLife", "ProgramToolGroup", "Measurements"});
item->setOrder({"Description", "CutterStatus", "Locus", "ItemLife",
"ProgramToolGroup", "Measurements"});

static auto items = make_shared<Factory>(Requirements {
{"count", INTEGER, true}, {"CuttingItem", ENTITY, item, 1, Requirement::Infinite}});
Expand Down
45 changes: 45 additions & 0 deletions test/cutting_tool_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -687,3 +687,48 @@ TEST_F(CuttingToolTest, test_xmlns_with_top_element_alias)
</CuttingTool>
)DOC");
}

TEST_F(CuttingToolTest, element_order_should_place_cutter_status_before_locus)
{
const auto doc =
R"DOC(<CuttingTool assetId="M8010W4194N1.2" deviceUuid="5fd88408-7811-3c6b-5400-11f4026b6890" serialNumber="0" timestamp="2022-07-12T22:38:38.2295Z" toolId="14076001">
<CuttingToolLifeCycle>
<CutterStatus>
<Status>USED</Status>
</CutterStatus>
<Location negativeOverlap="0" positiveOverlap="0" type="POT">2</Location>
<CuttingItems count="1">
<CuttingItem indices="1">
<Description>FACE MILL</Description>
<CutterStatus>
<Status>USED</Status>
<Status>AVAILABLE</Status>
<Status>ALLOCATED</Status>
</CutterStatus>
<Locus>12</Locus>
<ItemLife countDirection="UP" initial="0" limit="0" type="MINUTES" warning="80">4858</ItemLife>
<ItemLife countDirection="UP" initial="0" limit="0" type="PART_COUNT" warning="80">523</ItemLife>
<ProgramToolGroup>14076001</ProgramToolGroup>
<Measurements>
<CuttingDiameter nominal="76">76.16299</CuttingDiameter>
<FunctionalLength>259.955</FunctionalLength>
</Measurements>
</CuttingItem>
</CuttingItems>
</CuttingToolLifeCycle>
</CuttingTool>
)DOC";

ErrorList errors;
entity::XmlParser parser;

auto entity = parser.parse(Asset::getRoot(), doc, "2.0", errors);
ASSERT_EQ(0, errors.size());

// Round trip test
entity::XmlPrinter printer;
printer.print(*m_writer, entity, {});
string content = m_writer->getContent();

ASSERT_EQ(content, doc);
}

0 comments on commit 2dc0f67

Please sign in to comment.