| # |
| # 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. |
| # |
| # should be the same as what's in the docs, apart from this line |
| |
| name: Simple Netcat with Client |
| |
| location: localhost |
| |
| services: |
| |
| # the netcat server instance, running in listener mode (-l) |
| - type: org.apache.brooklyn.entity.software.base.VanillaSoftwareProcess |
| id: netcat-server |
| name: Simple Netcat Server |
| launch.command: | |
| echo hello | nc -l 4321 >> server-input & |
| echo $! > $PID_FILE |
| |
| # a failure detector and a service restarter work together |
| brooklyn.enrichers: |
| - type: org.apache.brooklyn.policy.ha.ServiceFailureDetector |
| brooklyn.config: |
| # wait 15s after service fails before propagating failure |
| serviceFailedStabilizationDelay: 15s |
| |
| brooklyn.policies: |
| - policyType: org.apache.brooklyn.policy.ha.ServiceRestarter |
| brooklyn.config: |
| # repeated failures in a time window can cause the restarter to abort, |
| # propagating the failure; a time window of 0 will mean it always restarts! |
| failOnRecurringFailuresInThisDuration: 0 |
| |
| brooklyn.initializers: |
| # two sensors, recording the data sent to this netcat server: |
| |
| - type: org.apache.brooklyn.core.sensor.ssh.SshCommandSensor |
| brooklyn.config: |
| name: output.last |
| command: tail -1 server-input |
| period: 100ms |
| |
| - type: org.apache.brooklyn.core.sensor.ssh.SshCommandSensor |
| brooklyn.config: |
| name: output.all |
| command: cat server-input |
| period: 100ms |
| |
| # a client to hit netcat |
| - type: org.apache.brooklyn.entity.software.base.VanillaSoftwareProcess |
| name: Simple Pinger |
| |
| # set the hostname of the netcat instance as an env var for the scripts |
| env: |
| TARGET_HOSTNAME: $brooklyn:component("netcat-server").attributeWhenReady("host.name") |
| |
| # start/check/stop are no-op |
| launch.command: "" |
| checkRunning.command: "" |
| stop.command: "" |
| |
| brooklyn.initializers: |
| # but there is a sample effector which runs nc in client mode |
| |
| - type: org.apache.brooklyn.core.effector.ssh.SshCommandEffector |
| brooklyn.config: |
| name: sayHiNetcat |
| description: Echo a small hello string to the netcat entity |
| command: | |
| echo $message | nc $TARGET_HOSTNAME 4321 |
| parameters: |
| message: |
| description: The string to pass to netcat |
| defaultValue: hi netcat |
| |
| # and add an enricher at the root so all sensors from netcat-server are visible on the root |
| brooklyn.enrichers: |
| - enricherType: org.apache.brooklyn.enricher.stock.Propagator |
| brooklyn.config: |
| enricher.producer: $brooklyn:component("netcat-server") |
| enricher.propagating.propagatingAll: true |