List of usage examples for com.amazonaws.services.route53.model HostedZone HostedZone
public HostedZone(String id, String name, String callerReference)
From source file:com.msi.dns53.server.AccessMySQL.java
License:Apache License
/** * Returns hashmap of <KEY: zoneID, VALUE: String[] of ID, name, caller * reference, and comment>/* w w w . j ava 2 s .co m*/ * * @param marker_tableName * table name of the marker * @param maxItems * number of items returned when the actual number of list * exceeds maxItems * @return Hashmap of <KEY: zoneID, VALUE: String[] of ID, name, caller * reference, and comment> * @throws InternalErrorException */ @Override public ListHostedZonesResult listHostedZones(String marker, int maxItems, long accId) throws ErrorResponse { ListHostedZonesResult result = new ListHostedZonesResult(); Collection<HostedZone> hostedZones = new LinkedList<HostedZone>(); int lim = maxItems; try { ResultSet rs = null; String query = null; Statement stmt = this.sqlConnection.createStatement(); if (marker == null) { logger.debug("No marker is given."); query = "SELECT * FROM msi.zones WHERE accountId = " + accId + ";"; } else { logger.debug("Marker is assigned."); query = "SELECT * FROM msi.zones WHERE accountId = " + accId + " AND ID >= \'" + marker + "\';"; } rs = stmt.executeQuery(query); while (lim != 0 && rs.next()) { HostedZone hz = new HostedZone(rs.getString("ID"), rs.getString("name"), rs.getString("callerReference")); HostedZoneConfig config = new HostedZoneConfig(); config.setComment(rs.getString("comment")); hz.setConfig(config); --lim; hostedZones.add(hz); } if (marker != null && hostedZones.size() == 0) { // TODO throw an exception for marker not existing (test against // AWS to see which exception is being returned) } boolean truncated = rs.next(); logger.debug("Relative Limit = " + lim + "; MaxItems = " + maxItems); logger.debug("Truncated = " + truncated); if (lim == 0 && truncated) { truncated = true; } result.setHostedZones(hostedZones); result.setMaxItems(String.valueOf(maxItems)); result.setIsTruncated(truncated); if (truncated) { result.setNextMarker(rs.getString("ID")); } } catch (SQLException e) { System.err.println("Failed to get zone informations for listHostedZone request."); e.printStackTrace(); throw DNS53Faults.InternalError(); } logger.debug("Returning " + hostedZones.size() + " hosted zones information."); return result; }
From source file:com.msi.dns53.server.query.CreateHostedZone.java
License:Apache License
private CreateHostedZoneResult createHostedZone(Session session, CreateHostedZoneRequest request) throws ErrorResponse { CreateHostedZoneResult result = new CreateHostedZoneResult(); Date submittedAt = new Date(); AccessMySQL sqlaccess = AccessMySQL.getInstance(); String name = request.getName(); try {/*from w w w .j a v a 2 s.c o m*/ new java.net.URI("http://" + name); } catch (URISyntaxException e) { throw DNS53Faults.InvalidDomainName(); } String comment = null; if (request.getHostedZoneConfig() != null) { comment = request.getHostedZoneConfig().getComment(); } List<String> zoneInfo = sqlaccess.createHostedZone(session, name, request.getCallerReference(), comment, this.getAccountId()); String zoneId = zoneInfo.get(0); if (zoneId.equals("DUPLICATE_REFERENCE")) { throw DNS53Faults.HostedZoneAlreadyExists(); } else if (zoneId.equals("DUPLICATE_NAME")) { throw DNS53Faults.DelegationSetNotAvailable(); } else { String status = DNS53Constants.PENDING; String tableName = zoneInfo.get(1); String changeID = RequestHandler.writeChange(sqlaccess, status, submittedAt.toString(), tableName, "CREATE"); HostedZone hz = new HostedZone(zoneId, request.getName(), request.getCallerReference()); hz.setConfig(request.getHostedZoneConfig()); result.setHostedZone(hz); ChangeInfo ci = new ChangeInfo(changeID, status, submittedAt); result.setChangeInfo(ci); List<String> nameServers = new LinkedList<String>(); for (int i = 2; i < zoneInfo.size(); ++i) { nameServers.add(zoneInfo.get(i)); } DelegationSet ds = new DelegationSet(nameServers); result.setDelegationSet(ds); } return result; }