name: Netcat Example 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 brooklyn.config: 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: - type: 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 period: 1s command: tail -1 server-input - type: org.apache.brooklyn.core.sensor.ssh.SshCommandSensor brooklyn.config: name: output.all period: 1s command: cat server-input # a client to hit netcat - type: org.apache.brooklyn.entity.software.base.VanillaSoftwareProcess name: Simple Pinger brooklyn.config: # set the hostname of the netcat instance as an env var for the scripts shell.env: TARGET_HOSTNAME: $brooklyn:entity("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: | # Uncomment the appropriate command for your operating system # for Linux: # echo $message | nc -N $TARGET_HOSTNAME 4321 # for MacOS: # 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: - type: org.apache.brooklyn.enricher.stock.Propagator brooklyn.config: enricher.producer: $brooklyn:entity("netcat-server") enricher.propagating.propagatingAll: true