@Override public void writeProfile(Account account, Map<String, Object> profile) throws IOException { try { Connection conn = dbConnectionPool.getConnection(); try { DBPut profilePut = new ProfileDBPut(account, profile); profilePut.executePut(conn); } finally { conn.close(); } } catch (SQLException e) { LOG.error("Exception writing profile for account {}.", account, e); throw new IOException(e); } }
@Override void setValue(String tenantId, String clusterId, byte[] val) throws IOException { try { Connection conn = dbConnectionPool.getConnection(); try { DBPut profilePut = new FieldsDBPut(tenantId, clusterId, val); profilePut.executePut(conn); } finally { conn.close(); } } catch (SQLException e) { LOG.error("Exception writing sensitive fields for tenant {} and cluster {}.", tenantId, clusterId, e); throw new IOException(e); } }
@Override protected void writeEntity(EntityType entityType, String entityName, int version, byte[] data) throws IOException { try { Connection conn = dbConnectionPool.getConnection(); try { DBPut entityPut = new EntityDBPut(entityType, entityName, version, data); entityPut.executePut(conn); } finally { conn.close(); } } catch (SQLException e) { throw new IOException("Exception writing entity of type " + entityType.name().toLowerCase() + " with name " + entityName + accountErrorSnippet); } }
@Override public void writeTenant(Tenant tenant) throws IOException { try { Connection conn = dbConnectionPool.getConnection(); try { DBPut tenantPut = new TenantDBPut(tenant, dbQueryExecutor.toBytes(tenant, Tenant.class)); tenantPut.executePut(conn); } finally { conn.close(); } } catch (SQLException e) { LOG.error("Exception writing tenant {}", tenant); throw new IOException(e); } }
@Override public void writeNode(Node node) throws IOException { try { Connection conn = dbConnectionPool.getConnection(); try { byte[] nodeBytes = dbQueryExecutor.toBytes(node, Node.class); DBPut nodePut = new NodeDBPut(node, nodeBytes); nodePut.executePut(conn); } finally { conn.close(); } } catch (SQLException e) { throw new IOException(e); } }
@Override public void writeProvisioner(Provisioner provisioner) throws IOException { Connection conn = null; try { conn = dbConnectionPool.getConnection(false); try { DBPut provisionerPut = new ProvisionerDBPut(provisioner, dbQueryExecutor.toBytes(provisioner, Provisioner.class)); provisionerPut.executePut(conn); writeProvisionerWorkers(conn, provisioner); conn.commit(); } finally { conn.close(); } } catch (SQLException e) { LOG.error("Exception writing provisioner, will attempt to rollback.", e); if (conn != null) { try { conn.rollback(); } catch (SQLException e1) { LOG.error("Exception rolling back failed provisioner write", e); } } throw new IOException("Exception writing cluster " + provisioner.getId(), e); } }
@Override public void writeClusterTask(ClusterTask clusterTask) throws IOException { TaskId taskId = TaskId.fromString(clusterTask.getTaskId()); long clusterId = Long.parseLong(taskId.getClusterId()); try { Connection conn = dbConnectionPool.getConnection(); try { byte[] taskBytes = dbQueryExecutor.toBytes(clusterTask, ClusterTask.class); DBPut taskPut = new ClusterTaskDBPut(clusterTask, taskBytes, taskId, clusterId); taskPut.executePut(conn); } finally { conn.close(); } } catch (SQLException e) { throw new IOException(e); } }
@Override public void writeClusterJob(ClusterJob clusterJob) throws IOException { JobId jobId = JobId.fromString(clusterJob.getJobId()); long clusterId = Long.parseLong(jobId.getClusterId()); try { Connection conn = dbConnectionPool.getConnection(); try { byte[] jobBytes = dbQueryExecutor.toBytes(clusterJob, ClusterJob.class); DBPut jobPut = new ClusterJobDBPut(clusterJob, jobBytes, jobId, clusterId); jobPut.executePut(conn); } finally { conn.close(); } } catch (SQLException e) { throw new IOException(e); } }
@Override public void writeNode(final Node node) throws IllegalAccessException, IOException { if (!allowedToWrite(node)) { throw new IllegalAccessException("Not allowed to write node " + node.getId()); } try { Connection conn = dbConnectionPool.getConnection(); try { byte[] nodeBytes = dbQueryExecutor.toBytes(node, Node.class); DBPut nodePut = new NodeDBPut(node, nodeBytes); nodePut.executePut(conn); } finally { conn.close(); } } catch (SQLException e) { throw new IOException("Exception writing node " + node.getId(), e); } }
@Override public void writeCluster(Cluster cluster) throws IllegalAccessException, IOException { if (!allowedToWrite(cluster)) { throw new IllegalAccessException("Not allowed to write cluster " + cluster.getId()); } long clusterNum = Long.parseLong(cluster.getId()); try { Connection conn = dbConnectionPool.getConnection(); try { byte[] clusterBytes = dbQueryExecutor.toBytes(cluster, Cluster.class); DBPut clusterPut = new ClusterDBPut(clusterNum, cluster, clusterBytes); clusterPut.executePut(conn); } finally { conn.close(); } } catch (SQLException e) { throw new IOException("Exception writing cluster " + cluster.getId(), e); } }