Package org.platformlayer.ops

Examples of org.platformlayer.ops.Machine


    }
    return networkPoint;
  }

  public NetworkPoint findNetworkPoint(ItemBase item) throws OpsException {
    Machine machine = instances.findMachine(item);
    if (machine == null) {
      log.warn("Unable to resolve item to machine: " + item.getKey());
      return null;
    }
    return machine.getNetworkPoint();
  }
View Full Code Here


      }

      // TODO: We could have a 'cluster key' that is used to tag the
      // machines providing this service

      Machine machine = instances.findMachine(dnsServer);
      if (machine == null) {
        log.warn("Dns server instance not found: " + dnsServer);
        failed = true;
        continue;
      }

      OpsTarget target = machine.getTarget(service.getSshKey());

      try {
        upload(target, dnsFile);
      } catch (OpsException e) {
        log.warn("Error updloading dns to server: " + dnsServer, e);
View Full Code Here

    // TODO: Idempotency etc
    // Machine machine = OpsContext.get().getInstance(Machine.class);
    NginxService nginxService = OpsContext.get().getInstance(NginxService.class);
    NginxFrontend nginxFrontend = OpsContext.get().getInstance(NginxFrontend.class);

    Machine machine = instanceHelpers.getMachine(nginxService);

    String address = machine.getNetworkPoint().getBestAddress(NetworkPoint.forPublicInternet());

    DnsRecord record = new DnsRecord();
    record.setDnsName(nginxFrontend.hostname);
    record.getAddress().add(address);
View Full Code Here

  private List<BackendModel> resolveBackends(List<NginxBackend> backends) throws OpsException {
    List<BackendModel> resolved = Lists.newArrayList();
    for (NginxBackend backend : backends) {
      ItemBase backendItem = platformLayer.getItem(backend.backend);

      Machine backendMachine = instances.getMachine(backendItem);

      int port = 0;
      if (port == 0) {
        port = 80;
      }

      // if (address.contains(":")) {
      // resolved.addAll(resolvePlatformLayer(address));
      // continue;
      // }

      // TODO: We need to register a dependency on the resolved item

      BackendModel model = new BackendModel();
      model.address = backendMachine.getNetworkPoint().getBestAddress(NetworkPoint.forTargetInContext());
      model.port = port;
      resolved.add(model);
    }
    return resolved;
  }
View Full Code Here

      ClusterServer model = new ClusterServer();
      model.key = server.clusterId;

      // TODO: What do we do about machines that don't yet have an ip?
      NetworkPoint targetNetworkPoint = NetworkPoint.forPublicInternet();
      Machine sourceMachine = instances.getMachine(server);
      String address = sourceMachine.getNetworkPoint().getBestAddress(targetNetworkPoint);

      model.ip = address;

      model.dnsName = ZookeeperUtils.buildDnsName(server);
View Full Code Here

            ItemBase sourceItem = platformLayerHelpers.getItem(sourceItemKey);

            NetworkPoint targetNetworkPoint = NetworkPoint.forTargetInContext();

            boolean required = !OpsContext.isDelete();
            Machine sourceMachine = instanceHelpers.getMachine(sourceItem, required);
            if (sourceMachine == null) {
              // TODO: Store by key? Delete by key?
              log.warn("Source machine not found for firewall rule; assuming already deleted");
              return null;
            }

            String sourceCidr = null;

            List<InetAddress> addresses = sourceMachine.getNetworkPoint().findAddresses(targetNetworkPoint);
            if (transport == Transport.Ipv4) {
              Iterables.removeIf(addresses, InetAddressUtils.IS_IPV6);

              if (addresses.size() == 1) {
                sourceCidr = addresses.get(0).getHostAddress() + "/32";
View Full Code Here

  @Inject
  PlatformLayerCloudHelpers cloudHelpers;

  @Handler
  public void handler(PersistentInstance model) throws OpsException {
    Machine machine = null;

    Tag tagForInstance = Tag.buildParentTag(model.getKey());
    // boolean instanceIsTagged = false;

    // See if we have an instance id tag
View Full Code Here

      tagger.platformLayerKey = model.getKey();
      tagger.tagChangesProvider = new OpsProvider<TagChanges>() {

        @Override
        public TagChanges get() throws OpsException {
          Machine machine = OpsContext.get().getInstance(Machine.class);

          if (machine == null) {
            if (OpsContext.isDelete()) {
              return null;
            }

            throw new OpsException("No machine in scope");
          }

          TagChanges changeTags = new TagChanges();
          changeTags.addTags.add(Tag.INSTANCE_KEY.build(machine.getKey()));
          platformLayer.changeTags(model.getKey(), changeTags, null);
          return changeTags;
        }
      };
      addChild(tagger);
View Full Code Here

      if (!Objects.equal(targetItemKey, machineItem.getKey())) {
        throw new OpsException("Expected to find same model");
      }

      Machine machine = instances.findMachine(machineItem);
      if (machine == null) {
        log.warn("Server instance not found: " + contextMachine);
        failed = true;
      } else {
        OpsTarget target = machine.getTarget(sshKey);
        failed |= processDataItems(controller, dataItems, machineItem, machine, target);
      }
    } else {
      // We are building a data item
      for (ItemBase machineItem : platformLayer.listItems(machineItemClass)) {
        if (machineItem.getState() != ManagedItemState.ACTIVE) {
          log.warn("Machine not yet active: " + machineItem);
          failed = true;
          continue;
        }

        Machine machine = instances.findMachine(machineItem);
        if (machine == null) {
          log.warn("Server instance not found: " + machineItem);
          failed = true;
          continue;
        }

        OpsTarget target = machine.getTarget(sshKey);

        failed |= processDataItems(controller, dataItems, machineItem, machine, target);
      }
    }
View Full Code Here

    PersistentInstance persistentInstanceTemplate = buildPersistentInstanceTemplate();

    persistentInstanceTemplate.getTags().add(parentTag);

    // Set during doOperation
    Machine machine = null;
    PersistentInstance persistentInstance = null;
    InstanceBase instance = null;
    OpsTarget target = null;

    persistentInstance = getOrCreate(parentTag, persistentInstanceTemplate);

    if (persistentInstance != null) {
      // We have to connect to the underlying machine not-via-DNS for Dns service => use instance id
      // TODO: Should we always use the instance id??

      instance = instances.findInstance(persistentInstance);
      if (instance == null && !OpsContext.isDelete()) {
        // A machine has not (yet) been assigned
        throw new OpsException("Machine is not yet built").setRetry(TimeSpan.ONE_MINUTE);
      }
    }

    if (instance != null) {
      machine = cloudHelpers.toMachine(instance);
    }

    if (addTagToManaged && !OpsContext.isDelete()) {
      // Add tag with instance id to persistent instance (very helpful for
      // DNS service!)
      PlatformLayerKey machineKey = machine.getKey();
      platformLayer.addTag(item.getKey(), Tag.INSTANCE_KEY.build(machineKey));
    }

    SshKey sshKey = service.getSshKey();
    if (machine != null) {
      if (OpsContext.isDelete()) {
        target = null;
        machine = null;
      } else {
        target = machine.getTarget(sshKey);
      }
    }

    RecursionState recursion = getRecursionState();
    if (OpsContext.isDelete() && machine == null) {
View Full Code Here

TOP

Related Classes of org.platformlayer.ops.Machine

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.