Пример #1
0
  @Override
  public void connectSensors() {
    super.connectSensors();
    connectServiceUpIsRunning();

    HostAndPort hostAndPort =
        BrooklynAccessUtils.getBrooklynAccessibleAddress(this, sensors().get(DOCKER_REGISTRY_PORT));
    sensors().set(Attributes.MAIN_URI, URI.create("https://" + hostAndPort + "/v2"));

    httpFeed =
        HttpFeed.builder()
            .entity(this)
            .period(Duration.seconds(3))
            .baseUri(getAttribute(Attributes.MAIN_URI))
            .poll(
                new HttpPollConfig<Boolean>(Attributes.SERVICE_UP)
                    .onSuccess(Functions.constant(true))
                    .onFailureOrException(Functions.constant(false)))
            .poll(
                new HttpPollConfig<List<String>>(DOCKER_REGISTRY_CATALOG)
                    .suburl("/_catalog")
                    .onSuccess(
                        Functionals.chain(
                            HttpValueFunctions.jsonContents(),
                            JsonFunctions.walk("repositories"),
                            JsonFunctions.forEach(JsonFunctions.cast(String.class))))
                    .onFailureOrException(Functions.constant(Collections.<String>emptyList())))
            .build();
  }
Пример #2
0
 @Override
 public void disconnectSensors() {
   if (httpFeed != null) {
     httpFeed.stop();
   }
   disconnectServiceUpIsRunning();
   super.disconnectSensors();
 }
Пример #3
0
  @Override
  public void init() {
    super.init();

    ConfigToAttributes.apply(this, DOCKER_HOST);
    ConfigToAttributes.apply(this, DOCKER_REGISTRY_PORT);

    DockerHost host = (DockerHost) sensors().get(DOCKER_HOST);
    String installDir = host.sensors().get(SoftwareProcess.INSTALL_DIR);
    SshMachineLocation sshMachine = host.getDynamicLocation().getMachine();
    String sshMachineInstallDir = getSSHMachineInstallDir();

    config()
        .set(
            DockerAttributes.DOCKER_PORT_BINDINGS,
            MutableMap.of(sensors().get(DOCKER_REGISTRY_PORT), 5000));
    config()
        .set(
            DockerAttributes.DOCKER_HOST_VOLUME_MAPPING,
            MutableMap.of(Os.mergePaths(installDir, "certs"), "/certs"));

    sshMachine.installTo(
        ImmutableMap.of(SshTool.PROP_PERMISSIONS.getName(), "0755"),
        SCRIPT_LOCATION,
        Os.mergePaths(sshMachineInstallDir, CREATE_CERTS_SCRIPT_NAME));
    sshMachine.installTo(
        config().get(DockerInfrastructure.DOCKER_CA_CERTIFICATE_PATH),
        Os.mergePaths(sshMachineInstallDir, "ca-cert.pem"));
    sshMachine.installTo(
        config().get(DockerInfrastructure.DOCKER_CA_KEY_PATH),
        Os.mergePaths(sshMachineInstallDir, "ca-key.pem"));

    int result =
        sshMachine.execCommands(
            "installCerts",
            ImmutableList.of(
                BashCommands.sudo(
                    String.format(
                        "%s %s %s",
                        Os.mergePaths(sshMachineInstallDir, CREATE_CERTS_SCRIPT_NAME),
                        host.sensors().get(Attributes.ADDRESS),
                        sshMachineInstallDir))));
    if (result != 0) {
      throw new IllegalStateException("Could not create certificates for docker registry");
    }
  }