示例#1
0
 public boolean update(Zone zone) {
   Connection conn = null;
   PreparedStatement st = null;
   ResultSet rs = null;
   try {
     conn = getConnection();
     st = conn.prepareStatement(UPDATE_ZONE);
     st.setString(1, zone.getName());
     st.setString(2, zone.getZonetype());
     st.setString(3, zone.getFormtype());
     st.setString(4, zone.getWorld());
     st.setString(5, zone.getAdmins());
     st.setString(6, zone.getUsers());
     st.setString(7, zone.getSettings());
     st.setInt(8, zone.getMiny());
     st.setInt(9, zone.getMaxy());
     st.setInt(10, zone.getSize());
     st.setString(11, zone.getConfig().toString());
     st.setInt(12, zone.getId());
     st.executeUpdate();
   } catch (Exception e) {
     Zones.log.warning("[Zones]Error updating " + zone.getName() + "[" + zone.getId() + "] :");
     e.printStackTrace();
     return false;
   } finally {
     try {
       if (conn != null) conn.close();
       if (st != null) st.close();
       if (rs != null) rs.close();
     } catch (Exception e) {
     }
   }
   return true;
 }
示例#2
0
  @Test(enabled = true)
  public void testRegisterTemplate() throws Exception {
    Zone zone = Iterables.getFirst(client.getZoneClient().listZones(), null);
    assertNotNull(zone);
    Iterable<Network> networks =
        client
            .getNetworkClient()
            .listNetworks(ListNetworksOptions.Builder.zoneId(zone.getId()).isDefault(true));
    networks =
        Iterables.filter(
            networks,
            new Predicate<Network>() {
              @Override
              public boolean apply(@Nullable Network network) {
                return network != null && network.getState().equals("Implemented");
              }
            });
    assertEquals(Iterables.size(networks), 1);
    Network network = Iterables.getOnlyElement(networks, null);
    assertNotNull(network);
    Set<OSType> osTypes = client.getGuestOSClient().listOSTypes();
    OSType osType = Iterables.getFirst(osTypes, null);

    // Register a template
    RegisterTemplateOptions options = RegisterTemplateOptions.Builder.bits(32).isExtractable(true);
    TemplateMetadata templateMetadata =
        TemplateMetadata.builder()
            .name(prefix + "-registerTemplate")
            .osTypeId(osType.getId())
            .displayText("jclouds live testRegisterTemplate")
            .build();
    Set<Template> templates =
        client
            .getTemplateClient()
            .registerTemplate(
                templateMetadata, "VHD", "XenServer", IMPORT_VHD_URL, zone.getId(), options);
    registeredTemplate = Iterables.getOnlyElement(templates, null);
    assertNotNull(registeredTemplate);

    // Ensure it is available
    final long zoneId = zone.getId();
    Predicate<Template> templateReadyPredicate =
        new Predicate<Template>() {
          @Override
          public boolean apply(@Nullable Template template) {
            if (template == null) return false;
            Template t2 = client.getTemplateClient().getTemplateInZone(template.getId(), zoneId);
            Logger.CONSOLE.info("%s", t2.getStatus());
            return "Download Complete".equals(t2.getStatus());
          }
        };
    assertTrue(
        new RetryablePredicate<Template>(templateReadyPredicate, 60000).apply(registeredTemplate));

    // Create a VM that uses this template
    vmForRegistration =
        VirtualMachineClientLiveTest.createVirtualMachineInNetwork(
            network, registeredTemplate.getId(), client, jobComplete, virtualMachineRunning);
    assertNotNull(vmForRegistration);
  }
示例#3
0
 public List<Vertice> get(Zone zone) {
   Connection conn = null;
   PreparedStatement st = null;
   ResultSet rs = null;
   List<Vertice> vertices = new ArrayList<Vertice>();
   try {
     conn = getConnection();
     st = conn.prepareStatement(SELECT_VERTICE);
     st.setInt(1, zone.getId());
     rs = st.executeQuery();
     while (rs.next()) {
       Vertice v = new Vertice();
       v.setId(rs.getInt(1));
       v.setVertexorder(rs.getInt(2));
       v.setX(rs.getInt(3));
       v.setZ(rs.getInt(4));
       vertices.add(v);
     }
   } catch (Exception e) {
     Zones.log.warning(
         "[Zones]Error loading vertices of " + zone.getName() + "[" + zone.getId() + "] :");
     e.printStackTrace();
   } finally {
     try {
       if (conn != null) conn.close();
       if (st != null) st.close();
       if (rs != null) rs.close();
     } catch (Exception e) {
     }
   }
   return vertices;
 }
示例#4
0
  @Test(enabled = true)
  public void testCreateTemplate() throws Exception {
    Zone zone = Iterables.getFirst(client.getZoneClient().listZones(), null);
    assertNotNull(zone);
    Iterable<Network> networks =
        client
            .getNetworkClient()
            .listNetworks(ListNetworksOptions.Builder.zoneId(zone.getId()).isDefault(true));
    networks =
        Iterables.filter(
            networks,
            new Predicate<Network>() {
              @Override
              public boolean apply(@Nullable Network network) {
                return network != null && network.getState().equals("Implemented");
              }
            });
    assertEquals(Iterables.size(networks), 1);
    Network network = Iterables.getOnlyElement(networks, null);
    assertNotNull(network);

    // Create a VM and stop it
    Long templateId = (imageId != null && !"".equals(imageId)) ? new Long(imageId) : null;
    vmForCreation =
        VirtualMachineClientLiveTest.createVirtualMachineInNetwork(
            network, templateId, client, jobComplete, virtualMachineRunning);
    assertTrue(
        jobComplete.apply(
            client.getVirtualMachineClient().stopVirtualMachine(vmForCreation.getId())),
        vmForCreation.toString());

    // Work out the VM's volume
    Set<Volume> volumes =
        client
            .getVolumeClient()
            .listVolumes(ListVolumesOptions.Builder.virtualMachineId(vmForCreation.getId()));
    assertEquals(volumes.size(), 1);
    Volume volume = Iterables.getOnlyElement(volumes);

    // Create a template
    CreateTemplateOptions options = CreateTemplateOptions.Builder.volumeId(volume.getId());
    AsyncCreateResponse response =
        client
            .getTemplateClient()
            .createTemplate(
                TemplateMetadata.builder()
                    .name(prefix + "-createTemplate")
                    .osTypeId(vmForCreation.getGuestOSId())
                    .displayText("jclouds live testCreateTemplate")
                    .build(),
                options);
    assertTrue(jobComplete.apply(response.getJobId()), vmForCreation.toString());
    createdTemplate =
        client.getTemplateClient().getTemplateInZone(response.getId(), vmForCreation.getZoneId());

    // Assertions
    assertNotNull(createdTemplate);
  }
示例#5
0
 public boolean save(Zone zone) {
   Connection conn = null;
   PreparedStatement st = null;
   ResultSet rs = null;
   try {
     conn = getConnection();
     st = conn.prepareStatement(SAVE_ZONE, Statement.RETURN_GENERATED_KEYS);
     st.setString(1, zone.getName());
     st.setString(2, zone.getZonetype());
     st.setString(3, zone.getFormtype());
     st.setString(4, zone.getWorld());
     st.setString(5, zone.getAdmins());
     st.setString(6, zone.getUsers());
     st.setString(7, zone.getSettings());
     st.setInt(8, zone.getMiny());
     st.setInt(9, zone.getMaxy());
     st.setInt(10, zone.getSize());
     st.setString(11, zone.getConfig().toString());
     st.execute();
     rs = st.getGeneratedKeys();
     if (rs.next()) {
       zone.setId(rs.getInt(1));
     }
   } catch (Exception e) {
     Zones.log.warning("[Zones]Error deleting " + zone.getName() + "[" + zone.getId() + "] :");
     e.printStackTrace();
     return false;
   } finally {
     try {
       if (conn != null) conn.close();
       if (st != null) st.close();
       if (rs != null) rs.close();
     } catch (Exception e) {
     }
   }
   if (zone.getId() == 0) return false;
   for (Vertice vertice : zone.getVertices()) {
     vertice.setId(zone.getId());
     save(vertice);
   }
   return true;
 }
示例#6
0
  @Override
  public void paint(Graphics graphics) {
    super.paint(graphics);

    Graphics2D g = (Graphics2D) graphics;

    if (shot != null) {
      for (Zone zone : shot.getZones().getZonesList()) {
        if (!"default-zone".equalsIgnoreCase(zone.getId())) {
          try {
            Polygon p = zone.getShape().getPolygon();

            if (zone.getId() == null) g.setColor(Color.BLUE);
            else if (zone.getId().equalsIgnoreCase("stumps")) g.setColor(Color.GREEN);
            else g.setColor(Color.RED);

            g.fillPolygon(p);
            g.setColor(g.getColor().darker());
            g.drawPolygon(p);
          } catch (Exception ex) {
            //					ex.printStackTrace();
          }
        }
      }
    }

    Stroke s = g.getStroke();
    g.setColor(Color.ORANGE);
    g.setStroke(new BasicStroke(5));
    g.drawRect(150, 250, 100, 150);
    g.setStroke(s);

    if (ballLoc != null) {
      g.setColor(Color.BLACK);
      g.fillOval((int) ballLoc.getX() - 5, (int) ballLoc.getY() - 5, 10, 10);
    }
  }
示例#7
0
 public boolean deleteVertices(Zone zone) {
   Connection conn = null;
   PreparedStatement st = null;
   ResultSet rs = null;
   try {
     conn = getConnection();
     st = conn.prepareStatement(DELETE_VERTICE);
     st.setInt(1, zone.getId());
     st.execute();
   } catch (Exception e) {
     Zones.log.warning(
         "[Zones]Error deleting vertices of " + zone.getName() + "[" + zone.getId() + "] :");
     e.printStackTrace();
     return false;
   } finally {
     try {
       if (conn != null) conn.close();
       if (st != null) st.close();
       if (rs != null) rs.close();
     } catch (Exception e) {
     }
   }
   return true;
 }
示例#8
0
 public List<Zone> getWorld(String world) {
   Connection conn = null;
   PreparedStatement st = null;
   ResultSet rs = null;
   List<Zone> zones = new ArrayList<Zone>();
   try {
     conn = getConnection();
     st = conn.prepareStatement(SELECT_ZONES);
     st.setString(1, world);
     rs = st.executeQuery();
     Zone z = null;
     while (rs.next()) {
       if (z == null || z.getId() != rs.getInt("id")) {
         if (z != null) {
           zones.add(z);
         }
         z = new Zone();
         z.setId(rs.getInt("id"));
         z.setName(rs.getString("name"));
         z.setZonetype(rs.getString("zonetype"));
         z.setFormtype(rs.getString("formtype"));
         z.setWorld(rs.getString("world"));
         z.setAdmins(rs.getString("admins"));
         z.setUsers(rs.getString("users"));
         z.setSettings(rs.getString("settings"));
         z.setMinY(rs.getInt("minz"));
         z.setMaxY(rs.getInt("maxz"));
         z.setSize(rs.getInt("size"));
         z.setConfig(rs.getString("config"));
       }
       z.addVertice(Vertice.from(z, rs));
     }
     if (z != null) {
       zones.add(z);
     }
   } catch (Exception e) {
     Zones.log.warning("[Zones]Error loading zones of world " + world + ":");
     e.printStackTrace();
   } finally {
     try {
       if (conn != null) conn.close();
       if (st != null) st.close();
       if (rs != null) rs.close();
     } catch (Exception e) {
     }
   }
   return zones;
 }