http://git-wip-us.apache.org/repos/asf/aurora/blob/94276046/src/main/java/org/apache/aurora/scheduler/storage/db/views/Pairs.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/aurora/scheduler/storage/db/views/Pairs.java b/src/main/java/org/apache/aurora/scheduler/storage/db/views/Pairs.java deleted file mode 100644 index 106b7af..0000000 --- a/src/main/java/org/apache/aurora/scheduler/storage/db/views/Pairs.java +++ /dev/null @@ -1,38 +0,0 @@ -/** - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.aurora.scheduler.storage.db.views; - -import java.util.Map; - -import com.google.common.collect.ImmutableMap; - -import org.apache.aurora.common.collections.Pair; - -/** - * Utility class for translating collections of {@link Pair} to and from maps. - */ -public final class Pairs { - - private Pairs() { - // Utility class. - } - - public static <K, V> Map<K, V> toMap(Iterable<Pair<K, V>> pairs) { - ImmutableMap.Builder<K, V> map = ImmutableMap.builder(); - for (Pair<K, V> pair : pairs) { - map.put(pair.getFirst(), pair.getSecond()); - } - return map.build(); - } -}
http://git-wip-us.apache.org/repos/asf/aurora/blob/94276046/src/main/java/org/apache/aurora/scheduler/storage/log/SnapshotStoreImpl.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/aurora/scheduler/storage/log/SnapshotStoreImpl.java b/src/main/java/org/apache/aurora/scheduler/storage/log/SnapshotStoreImpl.java index 3258879..6462b80 100644 --- a/src/main/java/org/apache/aurora/scheduler/storage/log/SnapshotStoreImpl.java +++ b/src/main/java/org/apache/aurora/scheduler/storage/log/SnapshotStoreImpl.java @@ -13,27 +13,19 @@ */ package org.apache.aurora.scheduler.storage.log; -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.SQLException; import java.util.Arrays; -import java.util.List; import java.util.Map; import java.util.Set; import javax.inject.Inject; -import javax.sql.DataSource; import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Joiner; import com.google.common.base.Optional; import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; import com.google.common.collect.FluentIterable; import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Lists; -import com.google.inject.Injector; import org.apache.aurora.common.inject.TimedInterceptor.Timed; import org.apache.aurora.common.stats.SlidingStats; @@ -57,11 +49,6 @@ import org.apache.aurora.scheduler.storage.Storage; import org.apache.aurora.scheduler.storage.Storage.MutableStoreProvider; import org.apache.aurora.scheduler.storage.Storage.MutateWork.NoResult; import org.apache.aurora.scheduler.storage.Storage.Volatile; -import org.apache.aurora.scheduler.storage.db.DbModule; -import org.apache.aurora.scheduler.storage.db.DbStorage; -import org.apache.aurora.scheduler.storage.db.DbUtil; -import org.apache.aurora.scheduler.storage.db.EnumBackfill; -import org.apache.aurora.scheduler.storage.db.MigrationManager; import org.apache.aurora.scheduler.storage.entities.IHostAttributes; import org.apache.aurora.scheduler.storage.entities.IJobConfiguration; import org.apache.aurora.scheduler.storage.entities.IJobInstanceUpdateEvent; @@ -88,12 +75,6 @@ public class SnapshotStoreImpl implements SnapshotStore<Snapshot> { private static final Logger LOG = LoggerFactory.getLogger(SnapshotStoreImpl.class); - /** - * Number of rows to run in a single batch during dbsnapshot restore. - */ - private static final int DB_BATCH_SIZE = 20; - - private static final String DB_SCRIPT_FIELD = "dbscript"; private static final String LOCK_FIELD = "locks"; private static final String HOST_ATTRIBUTES_FIELD = "hosts"; private static final String QUOTA_FIELD = "quota"; @@ -110,73 +91,6 @@ public class SnapshotStoreImpl implements SnapshotStore<Snapshot> { } private final Iterable<SnapshotField> snapshotFields = Arrays.asList( - // Order is critical here. The DB snapshot should always be tried first to ensure - // graceful migration to DBTaskStore. Otherwise, there is a direct risk of losing the cluster. - // The following scenario illustrates how that can happen: - // - Dbsnapshot:ON, DBTaskStore:OFF - // - Scheduler is updated with DBTaskStore:ON, restarts and populates all tasks from snapshot - // - Should the dbsnapshot get applied last, all tables would be dropped and recreated BUT - // since there was no task data stored in dbsnapshot (DBTaskStore was OFF last time - // snapshot was cut), all tasks would be erased - // - If the above is not detected before a new snapshot is cut all tasks will be dropped the - // moment a new snapshot is created - new SnapshotField() { - @Override - public String getName() { - return DB_SCRIPT_FIELD; - } - - @Override - public void saveToSnapshot(MutableStoreProvider store, Snapshot snapshot) { - // No-op. - } - - @Override - public void restoreFromSnapshot(MutableStoreProvider store, Snapshot snapshot) { - if (snapshot.isSetDbScript()) { - LOG.info("Loading contents from legacy dbScript field"); - - Injector injector = DbUtil.createStorageInjector(DbModule.testModuleWithWorkQueue()); - - DbStorage tempStorage = injector.getInstance(DbStorage.class); - MigrationManager migrationManager = injector.getInstance(MigrationManager.class); - EnumBackfill enumBackfill = injector.getInstance(EnumBackfill.class); - - try (Connection c = ((DataSource) tempStorage.getUnsafeStoreAccess()).getConnection()) { - LOG.info("Dropping all tables"); - try (PreparedStatement drop = c.prepareStatement("DROP ALL OBJECTS")) { - drop.executeUpdate(); - } - - LOG.info("Restoring dbsnapshot. Row count: " + snapshot.getDbScript().size()); - // Partition the restore script into manageable size batches to avoid possible OOM - // due to large size DML statement. - List<List<String>> batches = Lists.partition(snapshot.getDbScript(), DB_BATCH_SIZE); - for (List<String> batch : batches) { - try (PreparedStatement restore = c.prepareStatement(Joiner.on("").join(batch))) { - restore.executeUpdate(); - } - } - } catch (SQLException e) { - throw new RuntimeException(e); - } - - try { - migrationManager.migrate(); - } catch (SQLException e) { - throw new RuntimeException(e); - } - - // This ensures any subsequently added enum values since the last snapshot exist in - // the db. - enumBackfill.backfill(); - - // Load the contents of the DB into the main storage. - Snapshot dbSnapshot = createSnapshot(tempStorage); - applySnapshot(dbSnapshot); - } - } - }, new SnapshotField() { @Override public String getName() { http://git-wip-us.apache.org/repos/asf/aurora/blob/94276046/src/main/resources/org/apache/aurora/scheduler/storage/db/AttributeMapper.xml ---------------------------------------------------------------------- diff --git a/src/main/resources/org/apache/aurora/scheduler/storage/db/AttributeMapper.xml b/src/main/resources/org/apache/aurora/scheduler/storage/db/AttributeMapper.xml deleted file mode 100644 index d49c90b..0000000 --- a/src/main/resources/org/apache/aurora/scheduler/storage/db/AttributeMapper.xml +++ /dev/null @@ -1,90 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" ?> -<!DOCTYPE mapper - PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> -<mapper namespace="org.apache.aurora.scheduler.storage.db.AttributeMapper"> - <cache type="org.apache.aurora.scheduler.storage.db.MyBatisCacheImpl"> - <property name="size" value="50000"/> - </cache> - <insert id="insert"> - INSERT INTO host_attributes ( - host, - mode, - slave_id - ) VALUES ( - #{host}, - #{mode, typeHandler=org.apache.aurora.scheduler.storage.db.typehandlers.MaintenanceModeTypeHandler}, - #{slaveId} - ) - </insert> - - <insert id="insertAttributeValues"> - INSERT INTO host_attribute_values ( - host_attribute_id, - name, - value - ) VALUES - <foreach item="attribute" collection="attributes" separator=","> - <foreach item="value" collection="attribute.values" open="(" separator="),(" close=")"> - (SELECT id FROM host_attributes WHERE slave_id = #{slaveId}), - #{attribute.name}, - #{value} - </foreach> - </foreach> - </insert> - - <delete id="deleteAttributeValues"> - <!-- This assumes the schema enables cascading deletes in the values table. --> - DELETE FROM host_attribute_values - WHERE host_attribute_id IN (SELECT id FROM host_attributes WHERE host = #{host}) - </delete> - - <update id="updateHostModeAndSlaveId"> - UPDATE host_attributes SET - mode = #{mode, typeHandler=org.apache.aurora.scheduler.storage.db.typehandlers.MaintenanceModeTypeHandler}, - slave_id = #{slaveId} - WHERE host = #{host} - </update> - - <resultMap id="hostAttributeResultMap" type="org.apache.aurora.gen.HostAttributes"> - <id column="a_id" /> - <result property="mode" - column="a_mode" - typeHandler="org.apache.aurora.scheduler.storage.db.typehandlers.MaintenanceModeTypeHandler" /> - <result property="host" column="a_host" /> - <result property="slaveId" column="a_slave_id" /> - <collection property="attributes" ofType="org.apache.aurora.gen.Attribute" columnPrefix="v_"> - <id column="name" property="name" /> - <collection property="values" ofType="String"> - <result column="value" /> - </collection> - </collection> - </resultMap> - - <sql id="unscoped_select"> - SELECT - a.id AS a_id, - a.host AS a_host, - a.mode AS a_mode, - a.slave_id AS a_slave_id, - v.id AS v_id, - v.name AS v_name, - v.value AS v_value - FROM host_attributes as a - // Left outer join since a host attribute may have an empty set of values (no matching rows). - LEFT OUTER JOIN host_attribute_values AS v ON v.host_attribute_id = a.id - </sql> - - <select id="select" resultMap="hostAttributeResultMap"> - <include refid="unscoped_select"/> - WHERE host = #{host} - </select> - - <select id="selectAll" resultMap="hostAttributeResultMap"> - <include refid="unscoped_select"/> - </select> - - <delete id="truncate"> - DELETE FROM host_attributes - </delete> -</mapper> http://git-wip-us.apache.org/repos/asf/aurora/blob/94276046/src/main/resources/org/apache/aurora/scheduler/storage/db/CronJobMapper.xml ---------------------------------------------------------------------- diff --git a/src/main/resources/org/apache/aurora/scheduler/storage/db/CronJobMapper.xml b/src/main/resources/org/apache/aurora/scheduler/storage/db/CronJobMapper.xml deleted file mode 100644 index 1434f45..0000000 --- a/src/main/resources/org/apache/aurora/scheduler/storage/db/CronJobMapper.xml +++ /dev/null @@ -1,109 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" ?> -<!-- - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - --> - -<!DOCTYPE mapper - PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> -<mapper namespace="org.apache.aurora.scheduler.storage.db.CronJobMapper"> - - <insert id="merge"> - MERGE INTO cron_jobs( - job_key_id, - creator_user, - cron_schedule, - <if test="job.cronCollisionPolicy != null"> - cron_collision_policy, - </if> - task_config_row_id, - instance_count - ) KEY(job_key_id) VALUES ( - ( - SELECT ID - FROM job_keys - WHERE role = #{job.key.role} - AND environment = #{job.key.environment} - AND name = #{job.key.name} - ), - #{job.owner.user}, - #{job.cronSchedule}, - <if test="job.cronCollisionPolicy != null"> - #{job.cronCollisionPolicy, typeHandler=org.apache.aurora.scheduler.storage.db.typehandlers.CronCollisionPolicyTypeHandler}, - </if> - #{task_config_id}, - #{job.instanceCount} - ) - </insert> - - <delete id="delete"> - DELETE FROM cron_jobs - WHERE job_key_id - IN (SELECT id - FROM job_keys - WHERE role = #{job.role} - AND environment = #{job.environment} - AND name = #{job.name}) - </delete> - - <delete id="truncate"> - DELETE FROM cron_jobs - </delete> - - <resultMap - id="cronJobWrapperResultMap" - type="org.apache.aurora.scheduler.storage.db.views.DbJobConfiguration"> - - <id column="c_id" /> - <result property="owner.user" column="creator_user"/> - <result - property="cronCollisionPolicy" - column="cron_collision_policy" - typeHandler="org.apache.aurora.scheduler.storage.db.typehandlers.CronCollisionPolicyTypeHandler"/> - <association - property="key" - resultMap="org.apache.aurora.scheduler.storage.db.JobKeyMapper.jobKeyMap" - columnPrefix="j_"/> - <association - property="taskConfig" - select="org.apache.aurora.scheduler.storage.db.TaskConfigMapper.selectConfig" - column="task_config_row_id" - foreignColumn="id"/> - </resultMap> - - <sql id="unscopedSelect"> - SELECT - c.id AS c_id, - c.creator_user AS creator_user, - c.cron_schedule AS cron_schedule, - c.cron_collision_policy AS cron_collision_policy, - c.task_config_row_id AS task_config_row_id, - c.instance_count AS instance_count, - j.role AS j_role, - j.environment AS j_environment, - j.name AS j_name - FROM cron_jobs AS c - INNER JOIN job_keys AS j ON j.id = c.job_key_id - </sql> - - <select id="selectAll" resultMap="cronJobWrapperResultMap"> - <include refid="unscopedSelect"/> - </select> - - <select id="select" resultMap="cronJobWrapperResultMap"> - <include refid="unscopedSelect"/> - WHERE j.role = #{job.role} - AND environment = #{job.environment} - AND name = #{job.name} - </select> -</mapper> http://git-wip-us.apache.org/repos/asf/aurora/blob/94276046/src/main/resources/org/apache/aurora/scheduler/storage/db/EnumValueMapper.xml ---------------------------------------------------------------------- diff --git a/src/main/resources/org/apache/aurora/scheduler/storage/db/EnumValueMapper.xml b/src/main/resources/org/apache/aurora/scheduler/storage/db/EnumValueMapper.xml deleted file mode 100644 index b1f9672..0000000 --- a/src/main/resources/org/apache/aurora/scheduler/storage/db/EnumValueMapper.xml +++ /dev/null @@ -1,15 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" ?> -<!DOCTYPE mapper - PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> -<mapper namespace="org.apache.aurora.scheduler.storage.db.EnumValueMapper"> - <insert id="addEnumValue"> - MERGE INTO ${table} ( - id, - name - ) VALUES ( - #{id}, - #{name} - ) - </insert> -</mapper> http://git-wip-us.apache.org/repos/asf/aurora/blob/94276046/src/main/resources/org/apache/aurora/scheduler/storage/db/FrameworkIdMapper.xml ---------------------------------------------------------------------- diff --git a/src/main/resources/org/apache/aurora/scheduler/storage/db/FrameworkIdMapper.xml b/src/main/resources/org/apache/aurora/scheduler/storage/db/FrameworkIdMapper.xml deleted file mode 100644 index 74568ab..0000000 --- a/src/main/resources/org/apache/aurora/scheduler/storage/db/FrameworkIdMapper.xml +++ /dev/null @@ -1,32 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" ?> -<!-- - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - --> -<!DOCTYPE mapper - PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> -<mapper namespace="org.apache.aurora.scheduler.storage.db.FrameworkIdMapper"> - <insert id="insert"> - MERGE INTO framework_id ( - id, - framework_id - ) KEY(id) VALUES ( - 1, - #{id} - ) - </insert> - - <select id="select" resultType="String"> - SELECT framework_id FROM framework_id - </select> -</mapper> http://git-wip-us.apache.org/repos/asf/aurora/blob/94276046/src/main/resources/org/apache/aurora/scheduler/storage/db/JobInstanceUpdateEventMapper.xml ---------------------------------------------------------------------- diff --git a/src/main/resources/org/apache/aurora/scheduler/storage/db/JobInstanceUpdateEventMapper.xml b/src/main/resources/org/apache/aurora/scheduler/storage/db/JobInstanceUpdateEventMapper.xml deleted file mode 100644 index 1b58406..0000000 --- a/src/main/resources/org/apache/aurora/scheduler/storage/db/JobInstanceUpdateEventMapper.xml +++ /dev/null @@ -1,33 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" ?> -<!-- - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - --> - -<!DOCTYPE mapper - PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> -<mapper namespace="org.apache.aurora.scheduler.storage.db.JobInstanceUpdateEventMapper"> - <insert id="insert"> - INSERT INTO job_instance_update_events ( - update_row_id, - action, - instance_id, - timestamp_ms - ) VALUES ( - <include refid="org.apache.aurora.scheduler.storage.db.JobUpdateDetailsMapper.select_update_row_id"/>, - #{event.action, typeHandler=org.apache.aurora.scheduler.storage.db.typehandlers.JobUpdateActionTypeHandler}, - #{event.instanceId}, - #{event.timestampMs} - ) - </insert> -</mapper> http://git-wip-us.apache.org/repos/asf/aurora/blob/94276046/src/main/resources/org/apache/aurora/scheduler/storage/db/JobKeyMapper.xml ---------------------------------------------------------------------- diff --git a/src/main/resources/org/apache/aurora/scheduler/storage/db/JobKeyMapper.xml b/src/main/resources/org/apache/aurora/scheduler/storage/db/JobKeyMapper.xml deleted file mode 100644 index 3b5a7c9..0000000 --- a/src/main/resources/org/apache/aurora/scheduler/storage/db/JobKeyMapper.xml +++ /dev/null @@ -1,47 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" ?> -<!-- - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - --> - -<!DOCTYPE mapper - PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> -<mapper namespace="org.apache.aurora.scheduler.storage.db.JobKeyMapper"> - <insert id="merge"> - MERGE INTO job_keys ( - role, - environment, - name - ) KEY(role, environment, name) VALUES ( - #{role}, - #{environment}, - #{name} - ) - </insert> - - <select id="selectAll" resultType="org.apache.aurora.gen.JobKey"> - SELECT * FROM job_keys - </select> - - <select id="selectAllRowIds" resultType="long"> - SELECT id FROM job_keys - </select> - - <delete id="deleteRow"> - DELETE FROM job_keys WHERE id = #{rowId} - </delete> - - <resultMap id="jobKeyMap" type="org.apache.aurora.gen.JobKey"> - <id column="id" /> - </resultMap> -</mapper> http://git-wip-us.apache.org/repos/asf/aurora/blob/94276046/src/main/resources/org/apache/aurora/scheduler/storage/db/JobUpdateDetailsMapper.xml ---------------------------------------------------------------------- diff --git a/src/main/resources/org/apache/aurora/scheduler/storage/db/JobUpdateDetailsMapper.xml b/src/main/resources/org/apache/aurora/scheduler/storage/db/JobUpdateDetailsMapper.xml deleted file mode 100644 index aded483..0000000 --- a/src/main/resources/org/apache/aurora/scheduler/storage/db/JobUpdateDetailsMapper.xml +++ /dev/null @@ -1,598 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" ?> -<!-- - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - --> - -<!DOCTYPE mapper - PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> -<mapper namespace="org.apache.aurora.scheduler.storage.db.JobUpdateDetailsMapper"> - <sql id="job_key_inner_join"> - INNER JOIN job_keys AS j ON j.id = u.job_key_id - </sql> - - <sql id="filter_by_update_key"> - u.update_id = #{key.id} - AND j.role = #{key.job.role} - AND j.environment = #{key.job.environment} - AND j.name = #{key.job.name} - </sql> - - <sql id="select_update_row_id"> - ( - SELECT u.id - FROM job_updates AS u - <!-- Full qualification is needed since this fragment is accessed from outside of this - mapper. Without full qualification, mybatis looks for job_key_inner_join in the - caller's namespace. It's unclear if this is a feature or bug in mybatis. - --> - <include refid="org.apache.aurora.scheduler.storage.db.JobUpdateDetailsMapper.job_key_inner_join"/> - WHERE <include refid="org.apache.aurora.scheduler.storage.db.JobUpdateDetailsMapper.filter_by_update_key"/> - ) - </sql> - - <insert id="insert"> - INSERT INTO job_updates ( - job_key_id, - update_id, - user, - update_group_size, - max_per_instance_failures, - max_failed_instances, - min_wait_in_instance_running_ms, - rollback_on_failure, - wait_for_batch_completion, - block_if_no_pulses_after_ms - ) VALUES ( - ( - SELECT ID - FROM job_keys - WHERE role = #{summary.key.job.role} - AND environment = #{summary.key.job.environment} - AND name = #{summary.key.job.name} - ), - #{summary.key.id}, - #{summary.user}, - #{instructions.settings.updateGroupSize}, - #{instructions.settings.maxPerInstanceFailures}, - #{instructions.settings.maxFailedInstances}, - #{instructions.settings.minWaitInInstanceRunningMs}, - #{instructions.settings.rollbackOnFailure}, - #{instructions.settings.waitForBatchCompletion}, - #{instructions.settings.blockIfNoPulsesAfterMs}, - ) - </insert> - - <insert id="insertLockToken"> - INSERT INTO job_update_locks ( - update_row_id, - lock_token - ) VALUES ( - <include refid="select_update_row_id"/>, - #{lockToken} - ) - </insert> - - <insert id="insertTaskConfig" useGeneratedKeys="true" keyColumn="id" keyProperty="result.id"> - INSERT INTO job_update_configs ( - update_row_id, - task_config_row_id, - is_new - ) VALUES ( - <include refid="select_update_row_id"/>, - #{taskConfigRow}, - #{isNew} - ) - </insert> - - <insert id="insertJobUpdateMetadata"> - INSERT INTO job_update_metadata ( - update_row_id, - key, - value - ) VALUES - <foreach item="element" collection="metadata" open="(" separator="),(" close=")"> - <include refid="select_update_row_id"/>, - #{element.key}, - #{element.value} - </foreach> - </insert> - - <sql id="insert_instance_ranges"> - <foreach item="element" collection="ranges" open="(" separator="),(" close=")"> - <include refid="select_update_row_id"/>, - #{element.first}, - #{element.last} - </foreach> - </sql> - - <insert id="insertTaskConfigInstances"> - INSERT INTO job_update_configs_to_instances ( - config_id, - first, - last - ) VALUES - <foreach item="element" collection="ranges" open="(" separator="),(" close=")"> - #{configId}, - #{element.first}, - #{element.last} - </foreach> - </insert> - - <insert id="insertInstanceOverrides"> - INSERT INTO job_updates_to_instance_overrides ( - update_row_id, - first, - last - ) VALUES - <include refid="insert_instance_ranges" /> - </insert> - - <insert id="insertDesiredInstances"> - INSERT INTO job_updates_to_desired_instances ( - update_row_id, - first, - last - ) VALUES - <include refid="insert_instance_ranges" /> - </insert> - - <resultMap id="jobUpdateStateMap" type="org.apache.aurora.gen.JobUpdateState"> - <id column="update_id" /> - <result property="status" - column="status" - typeHandler="org.apache.aurora.scheduler.storage.db.typehandlers.JobUpdateStatusTypeHandler" /> - </resultMap> - - <resultMap id="jobUpdateSummaryMap" type="org.apache.aurora.gen.JobUpdateSummary"> - <id column="update_id" property="key.id" javaType="String" /> - <association property="key.job" - resultMap="org.apache.aurora.scheduler.storage.db.JobKeyMapper.jobKeyMap" - columnPrefix="jk_"/> - <association property="state" - resultMap="jobUpdateStateMap" - columnPrefix="just_" /> - <collection property="metadata" - select="selectJobUpdateMetadata" - column="id" - foreignColumn="update_row_id"> - </collection> - </resultMap> - - <resultMap id="rangeMap" type="org.apache.aurora.gen.Range"> - <id column="id" /> - </resultMap> - - <resultMap - id="instanceConfigMap" - type="org.apache.aurora.scheduler.storage.db.views.DbInstanceTaskConfig"> - <id column="id" /> - <association - property="task" - select="org.apache.aurora.scheduler.storage.db.TaskConfigMapper.selectConfig" - column="task_config_row_id" - foreignColumn="row_id"/> - <collection property="instances" resultMap="rangeMap" columnPrefix="r_" notNullColumn="id" /> - </resultMap> - - <resultMap id="jobUpdateSettingsMap" type="org.apache.aurora.gen.JobUpdateSettings"> - <id column="id" /> - <collection property="updateOnlyTheseInstances" - select="selectInstanceOverrides" - column="id" - foreignColumn="update_row_id" /> - </resultMap> - - <resultMap - id="jobUpdateInstructionMap" - type="org.apache.aurora.scheduler.storage.db.views.DbJobUpdateInstructions"> - <id column="id" /> - <association property="desiredState" resultMap="instanceConfigMap" columnPrefix="ditc_" /> - <association property="settings" resultMap="jobUpdateSettingsMap" columnPrefix="juse_"/> - <collection property="initialState" - select="selectInstanceConfigs" - column="id" - foreignColumn="update_row_id" /> - </resultMap> - - <resultMap id="jobUpdateMap" type="org.apache.aurora.scheduler.storage.db.views.DbJobUpdate"> - <id column="u_id" /> - <association property="summary" resultMap="jobUpdateSummaryMap" columnPrefix="jusm_"/> - <association property="instructions" resultMap="jobUpdateInstructionMap" columnPrefix="jui_"/> - </resultMap> - - <resultMap id="metadataMap" type="org.apache.aurora.gen.Metadata"> - <id column="id" /> - </resultMap> - - <resultMap id="jobInstanceUpdateMap" type="org.apache.aurora.gen.JobInstanceUpdateEvent"> - <id column="id" /> - <result property="action" - column="action" - typeHandler="org.apache.aurora.scheduler.storage.db.typehandlers.JobUpdateActionTypeHandler"/> - </resultMap> - - <resultMap id="jobUpdateEventMap" type="org.apache.aurora.gen.JobUpdateEvent"> - <id column="id" /> - <result property="status" - column="status" - typeHandler="org.apache.aurora.scheduler.storage.db.typehandlers.JobUpdateStatusTypeHandler"/> - </resultMap> - - <resultMap - id="jobUpdateDetailsMap" - type="org.apache.aurora.scheduler.storage.db.views.DbStoredJobUpdateDetails"> - <id column="u_id" /> - <association property="details.update" resultMap="jobUpdateMap" /> - <collection property="details.updateEvents" - select="selectUpdateEvents" - column="u_id" - foreignColumn="update_row_id"> - </collection> - <collection property="details.instanceEvents" - select="selectInstanceEvents" - column="u_id" - foreignColumn="update_row_id"> - </collection> - </resultMap> - - <sql id="status_inner_join"> - INNER JOIN - ( - SELECT - e_s.update_row_id, - e_s.status - FROM job_update_events AS e_s - INNER JOIN - ( - SELECT - update_row_id, - MAX(timestamp_ms) AS timestamp_ms - FROM job_update_events - GROUP BY update_row_id - ) AS e_t ON e_t.update_row_id = e_s.update_row_id AND e_t.timestamp_ms = e_s.timestamp_ms - ) AS max_status ON max_status.update_row_id = u.id - </sql> - - <sql id="created_timestamp_inner_join"> - INNER JOIN - ( - SELECT - update_row_id, - MIN(timestamp_ms) AS timestamp_ms - FROM job_update_events - GROUP BY update_row_id - ) AS min_ts ON min_ts.update_row_id = u.id - </sql> - - <sql id="last_updated_timestamp_inner_join"> - INNER JOIN - ( - SELECT - update_row_id, - MAX(timestamp_ms) AS timestamp_ms - FROM - ( - SELECT - update_row_id, - timestamp_ms - FROM job_update_events - UNION ALL - SELECT - update_row_id, - timestamp_ms - FROM job_instance_update_events - ) - GROUP BY update_row_id - ) AS max_ts ON max_ts.update_row_id = u.id - </sql> - - <sql id="timestamps_inner_joins"> - <include refid="status_inner_join" /> - <include refid="created_timestamp_inner_join" /> - <include refid="last_updated_timestamp_inner_join" /> - </sql> - - <sql id="query_filter"> - <if test="key != null || role != null || user != null || jobKey != null || updateStatuses != null || limit != 0 || offset != 0"> - WHERE TRUE - <if test="key != null"> - AND <include refid="filter_by_update_key"/> - </if> - <if test="user != null">AND u.user = #{user}</if> - <if test="role != null">AND j.role = #{role}</if> - <if test="jobKey != null"> - AND j.role = #{jobKey.role} - AND j.name = #{jobKey.name} - AND j.environment = #{jobKey.environment} - </if> - <if test="updateStatuses != null and !updateStatuses.isEmpty()"> - AND (max_status.status IN - <foreach item="element" collection="updateStatuses" open="(" separator="," close="))"> - #{element, typeHandler=org.apache.aurora.scheduler.storage.db.typehandlers.JobUpdateStatusTypeHandler} - </foreach> - </if> - </if> - ORDER BY max_ts.timestamp_ms DESC - <if test="limit != 0">LIMIT #{limit}</if> - <if test="offset != 0">OFFSET #{offset}</if> - </sql> - - <select id="selectSummaries" resultMap="jobUpdateSummaryMap"> - SELECT - u.id AS id, - u.update_id AS update_id, - u.user AS user, - max_status.status AS just_status, - min_ts.timestamp_ms AS just_created_timestamp_ms, - max_ts.timestamp_ms AS just_last_modified_timestamp_ms, - j.id AS jk_id, - j.role AS jk_role, - j.environment AS jk_environment, - j.name AS jk_name - FROM job_updates AS u - <include refid="job_key_inner_join" /> - <include refid="timestamps_inner_joins" /> - <include refid="query_filter" /> - </select> - - <!--Column naming convention below follows the thrift object hierarchy and columnPrefix - attributes used in associations. - For example: jusm_just_status maps to JobUpdateSummary/JobUpdateState/status field.--> - <sql id="job_update_columns"> - u.id AS u_id, - u.id AS jusm_id, - u.update_id AS jusm_update_id, - u.user AS jusm_user, - max_status.status AS jusm_just_status, - min_ts.timestamp_ms AS jusm_just_created_timestamp_ms, - max_ts.timestamp_ms AS jusm_just_last_modified_timestamp_ms, - j.id AS jusm_jk_id, - j.role AS jusm_jk_role, - j.environment AS jusm_jk_environment, - j.name AS jusm_jk_name, - u.id AS jui_juse_id, - u.update_group_size AS jui_juse_update_group_size, - u.max_per_instance_failures AS jui_juse_max_per_instance_failures, - u.max_failed_instances AS jui_juse_max_failed_instances, - u.min_wait_in_instance_running_ms AS jui_juse_min_wait_in_instance_running_ms, - u.rollback_on_failure AS jui_juse_rollback_on_failure, - u.wait_for_batch_completion AS jui_juse_wait_for_batch_completion, - u.block_if_no_pulses_after_ms AS jui_juse_block_if_no_pulses_after_ms, - u.id AS jui_id, - cn.id AS jui_ditc_id, - cn.task_config_row_id AS jui_ditc_task_config_row_id, - di.id AS jui_ditc_r_id, - di.first AS jui_ditc_r_first, - di.last AS jui_ditc_r_last - </sql> - - <sql id="job_update_outer_joins"> - LEFT OUTER JOIN job_update_configs AS cn ON cn.update_row_id = u.id AND cn.is_new = TRUE - LEFT OUTER JOIN job_updates_to_desired_instances AS di ON di.update_row_id = u.id - </sql> - - <sql id="lock_outer_join"> - LEFT OUTER JOIN job_update_locks AS l on l.update_row_id = u.id - </sql> - - <sql id="unscoped_details_select"> - SELECT - <include refid="job_update_columns" />, - l.lock_token AS lock_token - FROM job_updates AS u - <include refid="job_key_inner_join" /> - <include refid="timestamps_inner_joins" /> - <include refid="job_update_outer_joins" /> - <include refid="lock_outer_join" /> - </sql> - - <!--Ideally, update instruction columns could be derived from job_update_columns above but that - hits against the limits of mybatis code reuse as specifying a common "jui_" column prefix - in case of a standalone (no parent association) select appears to be impossible.--> - <select id="selectInstructions" resultMap="jobUpdateInstructionMap"> - SELECT - u.id AS juse_id, - u.update_group_size AS juse_update_group_size, - u.max_per_instance_failures AS juse_max_per_instance_failures, - u.max_failed_instances AS juse_max_failed_instances, - u.min_wait_in_instance_running_ms AS juse_min_wait_in_instance_running_ms, - u.rollback_on_failure AS juse_rollback_on_failure, - u.wait_for_batch_completion AS juse_wait_for_batch_completion, - u.block_if_no_pulses_after_ms AS juse_block_if_no_pulses_after_ms, - u.id AS id, - cn.id AS ditc_id, - cn.task_config_row_id AS ditc_task_config_row_id, - di.id AS ditc_r_id, - di.first AS ditc_r_first, - di.last AS ditc_r_last - FROM job_updates AS u - <include refid="job_key_inner_join" /> - <include refid="job_update_outer_joins" /> - WHERE <include refid="filter_by_update_key"/> - </select> - - <select id="selectUpdate" resultMap="jobUpdateMap"> - SELECT - <include refid="job_update_columns" /> - FROM job_updates AS u - <include refid="job_key_inner_join" /> - <include refid="timestamps_inner_joins" /> - <include refid="job_update_outer_joins" /> - WHERE <include refid="filter_by_update_key"/> - </select> - - <select id="selectDetails" resultMap="jobUpdateDetailsMap"> - <include refid="unscoped_details_select"/> - WHERE <include refid="filter_by_update_key"/> - </select> - - <select id="selectDetailsList" resultMap="jobUpdateDetailsMap"> - <include refid="unscoped_details_select"/> - <include refid="query_filter"/> - </select> - - <select id="selectAllDetails" resultMap="jobUpdateDetailsMap"> - <include refid="unscoped_details_select"/> - </select> - - <select id="selectInstanceConfigs" resultMap="instanceConfigMap"> - SELECT - co.id, - co.task_config_row_id AS task_config_row_id, - ci.id AS r_id, - ci.first AS r_first, - ci.last AS r_last - FROM job_update_configs as co - INNER JOIN job_update_configs_to_instances AS ci ON ci.config_id = co.id - WHERE co.update_row_id = #{id} - AND co.is_new = FALSE - </select> - - <select id="selectInstanceOverrides" resultMap="rangeMap"> - SELECT - o.id, - o.first, - o.last - FROM job_updates_to_instance_overrides as o - WHERE update_row_id = #{id} - </select> - - <select id="selectInstanceUpdateEvents" resultMap="jobInstanceUpdateMap"> - SELECT - e.id, - instance_id, - timestamp_ms, - action - FROM job_instance_update_events as e - INNER JOIN job_updates as u ON u.id = e.update_row_id - <include refid="job_key_inner_join" /> - WHERE <include refid="filter_by_update_key"/> - AND e.instance_id = #{instanceId} - ORDER BY e.timestamp_ms - </select> - - <select id="selectUpdateEvents" resultMap="jobUpdateEventMap"> - SELECT - e.id, - status, - timestamp_ms, - e.user, - message - FROM job_update_events as e - WHERE update_row_id = #{id} - ORDER BY e.id - </select> - - <select id="selectInstanceEvents" resultMap="jobInstanceUpdateMap"> - SELECT - e.id, - instance_id, - timestamp_ms, - action - FROM job_instance_update_events as e - WHERE update_row_id = #{id} - ORDER BY e.id - </select> - - <select id="selectJobUpdateMetadata" resultMap="metadataMap"> - SELECT - m.id, - m.key, - m.value - FROM job_update_metadata as m - WHERE update_row_id = #{id} - </select> - - <delete id="truncate"> - DELETE FROM job_updates; - </delete> - - <select id="selectJobKeysForPruning" resultType="long"> - SELECT DISTINCT - u.job_key_id - FROM job_updates as u - <include refid="created_timestamp_inner_join" /> - <include refid="lock_outer_join" /> - WHERE l.id IS NULL - GROUP BY u.job_key_id - HAVING COUNT(u.job_key_id) > #{retainCount} - UNION - SELECT DISTINCT - u.job_key_id - FROM job_updates as u - <include refid="created_timestamp_inner_join" /> - <include refid="lock_outer_join" /> - WHERE min_ts.timestamp_ms < #{pruneThresholdMs} AND l.id IS NULL - </select> - - <resultMap id="jobUpdateKeyMap" type="org.apache.aurora.gen.JobUpdateKey"> - <association property="job" - resultMap="org.apache.aurora.scheduler.storage.db.JobKeyMapper.jobKeyMap" - columnPrefix="jk_"/> - </resultMap> - - <resultMap id="pruneVictimMap" type="org.apache.aurora.scheduler.storage.db.PruneVictim"> - <id column="row_id" property="rowId"/> - <association property="update" resultMap="jobUpdateKeyMap" columnPrefix="u_" /> - </resultMap> - - <select id="selectPruneVictims" resultMap="pruneVictimMap"> - SELECT - row_id, - u_id, - u_jk_role, - u_jk_environment, - u_jk_name - FROM - ( - SELECT - u.id as row_id, - u.update_id AS u_id, - j.role AS u_jk_role, - j.environment AS u_jk_environment, - j.name AS u_jk_name - FROM job_updates as u - <include refid="job_key_inner_join" /> - <include refid="created_timestamp_inner_join" /> - <include refid="lock_outer_join" /> - WHERE u.job_key_id = #{keyId} - AND l.id IS NULL - ORDER BY min_ts.timestamp_ms DESC - LIMIT NULL - OFFSET #{retainCount} - ) - UNION - SELECT - u.id, - u.update_id AS u_id, - j.role AS u_jk_role, - j.environment AS u_jk_environment, - j.name AS u_jk_name - FROM job_updates as u - <include refid="job_key_inner_join" /> - <include refid="created_timestamp_inner_join" /> - <include refid="lock_outer_join" /> - WHERE u.job_key_id = #{keyId} - AND min_ts.timestamp_ms <= #{pruneThresholdMs} - AND l.id IS NULL - </select> - - <delete id="deleteCompletedUpdates"> - DELETE FROM job_updates - WHERE id IN - <foreach item="element" collection="rowIds" open="(" separator="," close=")"> - #{element} - </foreach> - </delete> -</mapper> http://git-wip-us.apache.org/repos/asf/aurora/blob/94276046/src/main/resources/org/apache/aurora/scheduler/storage/db/JobUpdateEventMapper.xml ---------------------------------------------------------------------- diff --git a/src/main/resources/org/apache/aurora/scheduler/storage/db/JobUpdateEventMapper.xml b/src/main/resources/org/apache/aurora/scheduler/storage/db/JobUpdateEventMapper.xml deleted file mode 100644 index 910d830..0000000 --- a/src/main/resources/org/apache/aurora/scheduler/storage/db/JobUpdateEventMapper.xml +++ /dev/null @@ -1,35 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" ?> -<!-- - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - --> - -<!DOCTYPE mapper - PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> -<mapper namespace="org.apache.aurora.scheduler.storage.db.JobUpdateEventMapper"> - <insert id="insert"> - INSERT INTO job_update_events ( - update_row_id, - status, - user, - timestamp_ms, - message - ) VALUES ( - <include refid="org.apache.aurora.scheduler.storage.db.JobUpdateDetailsMapper.select_update_row_id"/>, - #{event.status, typeHandler=org.apache.aurora.scheduler.storage.db.typehandlers.JobUpdateStatusTypeHandler}, - #{event.user}, - #{event.timestampMs}, - #{event.message} - ) - </insert> -</mapper> http://git-wip-us.apache.org/repos/asf/aurora/blob/94276046/src/main/resources/org/apache/aurora/scheduler/storage/db/LockMapper.xml ---------------------------------------------------------------------- diff --git a/src/main/resources/org/apache/aurora/scheduler/storage/db/LockMapper.xml b/src/main/resources/org/apache/aurora/scheduler/storage/db/LockMapper.xml deleted file mode 100644 index ce8ed3a..0000000 --- a/src/main/resources/org/apache/aurora/scheduler/storage/db/LockMapper.xml +++ /dev/null @@ -1,83 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" ?> -<!-- - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - --> - -<!DOCTYPE mapper - PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> -<mapper namespace="org.apache.aurora.scheduler.storage.db.LockMapper"> - <insert id="insert"> - INSERT INTO locks ( - job_key_id, - token, - user, - timestampMs, - message - ) VALUES ( - ( - SELECT ID - FROM job_keys - WHERE role = #{key.job.role} - AND environment = #{key.job.environment} - AND name = #{key.job.name} - ), - #{token}, - #{user}, - #{timestampMs}, - #{message} - ) - </insert> - - <resultMap id="lockResultMap" type="org.apache.aurora.scheduler.storage.db.views.LockRow"> - <!-- - Normally you can have MyBatis auto-map these columns and/or use assocations, but - in this case we need to work-around thrift union type issues and prevent MyBatis - from trying to create new objects like it does with associations. - Explicitly mapping each column to a single base property (lock, here) does just that. - --> - <result column="token" property="lock.token"/> - <result column="user" property="lock.user"/> - <result column="timestampMs" property="lock.timestampMs"/> - <result column="message" property="lock.message"/> - <result column="role" property="lock.key.job.role"/> - <result column="environment" property="lock.key.job.environment"/> - <result column="name" property="lock.key.job.name"/> - </resultMap> - - <select id="selectAll" resultMap="lockResultMap"> - SELECT * FROM locks AS lock - JOIN job_keys AS key ON job_key_id = key.id - </select> - <sql id="jobKeyScope"> - JOIN job_keys AS key ON key.role = #{job.role} - AND key.environment = #{job.environment} - AND key.name = #{job.name} - AND key.id = job_key_id - </sql> - <select id="select" resultMap="lockResultMap"> - SELECT * FROM locks <include refid="jobKeyScope" /> - </select> - <delete id="delete"> - DELETE FROM locks - WHERE job_key_id - IN (SELECT id - FROM job_keys - WHERE role = #{job.role} - AND environment = #{job.environment} - AND name = #{job.name}) - </delete> - <delete id="truncate"> - DELETE FROM locks - </delete> -</mapper> http://git-wip-us.apache.org/repos/asf/aurora/blob/94276046/src/main/resources/org/apache/aurora/scheduler/storage/db/MigrationMapper.xml ---------------------------------------------------------------------- diff --git a/src/main/resources/org/apache/aurora/scheduler/storage/db/MigrationMapper.xml b/src/main/resources/org/apache/aurora/scheduler/storage/db/MigrationMapper.xml deleted file mode 100644 index f6881ac..0000000 --- a/src/main/resources/org/apache/aurora/scheduler/storage/db/MigrationMapper.xml +++ /dev/null @@ -1,55 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" ?> -<!-- - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - --> - -<!DOCTYPE mapper - PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> -<mapper namespace="org.apache.aurora.scheduler.storage.db.MigrationMapper"> - <update id="bootstrapChangelog"> - CREATE TABLE IF NOT EXISTS changelog ( - id BIGINT NOT NULL PRIMARY KEY, - applied_at VARCHAR(25) NOT NULL, - description VARCHAR(255) NOT NULL, - downgrade_script BLOB NULL, - - UNIQUE(id) - ); - </update> - - <update id="saveDowngradeScript"> - UPDATE changelog - SET downgrade_script = #{downgradeScript} - WHERE id = #{changeId} - </update> - - <resultMap - id="changelogResultMap" - type="org.apache.aurora.scheduler.storage.db.views.MigrationChangelogEntry"> - - </resultMap> - - <select id="selectAll" resultMap="changelogResultMap"> - SELECT - id, - downgrade_script - FROM changelog - ORDER BY id DESC - </select> - - <delete id="delete"> - DELETE FROM changelog - WHERE id = #{changeId} - </delete> -</mapper> http://git-wip-us.apache.org/repos/asf/aurora/blob/94276046/src/main/resources/org/apache/aurora/scheduler/storage/db/QuotaMapper.xml ---------------------------------------------------------------------- diff --git a/src/main/resources/org/apache/aurora/scheduler/storage/db/QuotaMapper.xml b/src/main/resources/org/apache/aurora/scheduler/storage/db/QuotaMapper.xml deleted file mode 100644 index 0f46968..0000000 --- a/src/main/resources/org/apache/aurora/scheduler/storage/db/QuotaMapper.xml +++ /dev/null @@ -1,91 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" ?> -<!-- - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - --> -<!DOCTYPE mapper - PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> -<mapper namespace="org.apache.aurora.scheduler.storage.db.QuotaMapper"> - <insert id="insert" useGeneratedKeys="true" keyColumn="id" keyProperty="result.id"> - INSERT INTO quotas ( - role, - num_cpus, - ram_mb, - disk_mb - ) VALUES ( - #{role}, - #{quota.numCpus}, - #{quota.ramMb}, - #{quota.diskMb} - ) - </insert> - - <insert id="insertResources"> - INSERT INTO quota_resource ( - quota_id, - type_id, - value - ) VALUES ( - <foreach index="type" item="value" collection="values" separator="),("> - #{quotaId}, - #{type}, - #{value} - </foreach> - ) - </insert> - - <resultMap id="quotaMap" type="org.apache.aurora.scheduler.storage.db.views.DBResourceAggregate"> - <id column="id" /> - <collection - property="resources" - columnPrefix="qr_" - resultMap="org.apache.aurora.scheduler.storage.db.TaskConfigMapper.resourceMap"/> - </resultMap> - - <resultMap id="quotaResultMap" type="org.apache.aurora.scheduler.storage.db.views.DBSaveQuota"> - <id column="id" /> - <association property="quota" resultMap="quotaMap" /> - </resultMap> - - <sql id="unscopedSelect"> - SELECT - q.id, - q.role, - q.num_cpus, - q.ram_mb, - q.disk_mb, - qr.id as qr_id, - qr.type_id as qr_type_id, - qr.value as qr_value - FROM quotas AS q - INNER JOIN quota_resource AS qr ON qr.quota_id = q.id - </sql> - - <select id="select" resultMap="quotaMap"> - <include refid="unscopedSelect"/> - WHERE role = #{id} - </select> - - <select id="selectAll" resultMap="quotaResultMap"> - <include refid="unscopedSelect"/> - </select> - - <delete id="delete"> - DELETE FROM quotas - WHERE role = #{id} - </delete> - - <delete id="truncate"> - DELETE FROM quotas - </delete> -</mapper> http://git-wip-us.apache.org/repos/asf/aurora/blob/94276046/src/main/resources/org/apache/aurora/scheduler/storage/db/TaskConfigMapper.xml ---------------------------------------------------------------------- diff --git a/src/main/resources/org/apache/aurora/scheduler/storage/db/TaskConfigMapper.xml b/src/main/resources/org/apache/aurora/scheduler/storage/db/TaskConfigMapper.xml deleted file mode 100644 index 5422183..0000000 --- a/src/main/resources/org/apache/aurora/scheduler/storage/db/TaskConfigMapper.xml +++ /dev/null @@ -1,460 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" ?> -<!-- - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - --> - -<!DOCTYPE mapper - PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> -<mapper namespace="org.apache.aurora.scheduler.storage.db.TaskConfigMapper"> - <cache type="org.apache.aurora.scheduler.storage.db.MyBatisCacheImpl"> - <property name="size" value="1000"/> - </cache> - <insert id="insert" useGeneratedKeys="true" keyColumn="id" keyProperty="result.id"> - INSERT INTO task_configs ( - job_key_id, - creator_user, - service, - num_cpus, - ram_mb, - disk_mb, - priority, - max_task_failures, - production, - contact_email, - executor_name, - executor_data, - tier - ) VALUES ( - ( - SELECT ID - FROM job_keys - WHERE role = #{config.job.role} - AND environment = #{config.job.environment} - AND name = #{config.job.name} - ), - #{config.owner.user}, - #{config.isService}, - #{config.numCpus}, - #{config.ramMb}, - #{config.diskMb}, - #{config.priority}, - #{config.maxTaskFailures}, - #{config.production}, - #{config.contactEmail}, - #{config.executorConfig.name}, - #{config.executorConfig.data}, - #{config.tier} - ) - </insert> - - <resultMap id="limitConstraintMap" type="org.apache.aurora.gen.LimitConstraint"> - <id column="id"/> - </resultMap> - - <resultMap id="valueConstraintMap" type="org.apache.aurora.gen.ValueConstraint"> - <id column="id"/> - - <collection property="values" ofType="String" columnPrefix="v_"> - <result column="value" /> - </collection> - </resultMap> - - <resultMap id="taskConstraintMap" type="org.apache.aurora.scheduler.storage.db.views.DbTaskConstraint"> - <id column="id"/> - <association property="value" resultMap="valueConstraintMap" columnPrefix="v_"/> - <association property="limit" resultMap="limitConstraintMap" columnPrefix="l_"/> - </resultMap> - - <resultMap id="constraintMap" type="org.apache.aurora.scheduler.storage.db.views.DbConstraint"> - <id column="id"/> - <association property="constraint" resultMap="taskConstraintMap"/> - </resultMap> - - <resultMap id="dockerParameterMap" type="org.apache.aurora.gen.DockerParameter"> - <id column="id"/> - </resultMap> - - <select id="selectDockerParameters" resultMap="dockerParameterMap"> - SELECT - id, - name, - value - FROM task_config_docker_container_parameters - WHERE container_id = #{id} - </select> - - <resultMap id="dockerContainerMap" type="org.apache.aurora.gen.DockerContainer"> - <id column="id"/> - <result column="docker_image" property="image"/> - <collection - property="parameters" - select="selectDockerParameters" - column="id" - foreignColumn="container_id"/> - </resultMap> - - <resultMap id="dockerImageMap" type="org.apache.aurora.gen.DockerImage"> - <id column="id" /> - </resultMap> - - <resultMap id="appcImageMap" type="org.apache.aurora.gen.AppcImage"> - <id column="id" /> - </resultMap> - - <resultMap id="imageMap" type="org.apache.aurora.scheduler.storage.db.views.DbImage"> - <association property="appc" columnPrefix="appc_" resultMap="appcImageMap" /> - <association property="docker" columnPrefix="docker_" resultMap="dockerImageMap" /> - </resultMap> - - <resultMap id="containerMap" type="org.apache.aurora.scheduler.storage.db.views.DbContainer"> - <!--NOTE: Do not put any collections under here. ContainerMap doesn't correspond to a table, it's a syntheic map - for assocations. Since it doesn't have a table, there is no unique id. Since there is no unique id, MyBatis nested - result map collections fail. - --> - <association property="docker" resultMap="dockerContainerMap" /> - <association property="image" columnPrefix="image_" resultMap="imageMap" /> - </resultMap> - - <resultMap id="metadataMap" type="org.apache.aurora.gen.Metadata"> - <id column="id" /> - </resultMap> - - <resultMap id="mesosFetcherUrisMap" type="org.apache.aurora.gen.MesosFetcherURI"> - <id column="id" /> - </resultMap> - - <resultMap id="volumeMap" type="org.apache.aurora.gen.Volume"> - <id column="id" /> - <result property="mode" column="mode" typeHandler="org.apache.aurora.scheduler.storage.db.typehandlers.VolumeModeTypeHandler" /> - </resultMap> - - <resultMap id="resourceMap" type="org.apache.aurora.scheduler.storage.db.views.DBResource"> - <id column="id" /> - <result property="type" - column="type_id" - typeHandler="org.apache.aurora.scheduler.storage.db.typehandlers.ResourceTypeHandler" /> - </resultMap> - - <resultMap id="taskConfigMap" type="org.apache.aurora.scheduler.storage.db.views.DbTaskConfig"> - <id column="id" property="rowId" /> - <result column="creator_user" property="owner.user"/> - <result column="executor_name" property="executorConfig.name"/> - <result column="executor_data" property="executorConfig.data"/> - <association - property="job" - resultMap="org.apache.aurora.scheduler.storage.db.JobKeyMapper.jobKeyMap" - columnPrefix="j_"/> - <association property="container" resultMap="containerMap" columnPrefix="c_"/> - <collection property="volumes" columnPrefix="volume_" resultMap="volumeMap" notNullColumn="id" /> - <collection - property="constraints" - columnPrefix="constraint_" - resultMap="constraintMap"/> - <collection property="requestedPorts" ofType="String" columnPrefix="p_"> - <result column="port_name" /> - </collection> - <collection property="metadata" resultMap="metadataMap" columnPrefix="m_"/> - <collection property="mesosFetcherUris" resultMap="mesosFetcherUrisMap" columnPrefix="u_"/> - <collection - property="taskLinks" - select="selectTaskLinks" - column="id" - foreignColumn="task_config_id"/> - <!-- TODO(maxim): move resources to a main join when task level fields are removed. --> - <collection - property="resources" - select="selectResources" - column="id" - foreignColumn="task_config_id" /> - </resultMap> - - <sql id="unscopedConfigSelect"> - SELECT - c.id AS id, - c.creator_user AS creator_user, - c.service AS is_service, - c.num_cpus AS num_cpus, - c.ram_mb AS ram_mb, - c.disk_mb AS disk_mb, - c.priority AS priority, - c.max_task_failures AS max_task_failures, - c.production AS production, - c.contact_email AS contact_email, - c.executor_name AS executor_name, - c.executor_data AS executor_data, - c.tier AS tier, - j.role AS j_role, - j.environment AS j_environment, - j.name AS j_name, - p.port_name AS p_port_name, - d.id AS c_id, - d.image AS c_docker_image, - m.id AS m_id, - m.key AS m_key, - m.value AS m_value, - u.id AS u_id, - u.value AS u_value, - u.extract AS u_extract, - u.cache AS u_cache, - di.name as c_image_docker_name, - di.tag as c_image_docker_tag, - ai.name as c_image_appc_name, - ai.image_id as c_image_appc_image_id, - v.id as volume_id, - v.host_path as volume_host_path, - v.container_path as volume_container_path, - v.mode as volume_mode, - tc.id AS constraint_id, - tc.name AS constraint_name, - tlc.id AS constraint_l_id, - tlc.value AS constraint_l_limit, - tvc.id AS constraint_v_id, - tvc.negated AS constraint_v_negated, - tvcv.value as constraint_v_v_value - FROM task_configs AS c - INNER JOIN job_keys AS j ON j.id = c.job_key_id - LEFT OUTER JOIN task_config_requested_ports AS p ON p.task_config_id = c.id - LEFT OUTER JOIN task_config_docker_containers AS d ON d.task_config_id = c.id - LEFT OUTER JOIN task_config_metadata AS m ON m.task_config_id = c.id - LEFT OUTER JOIN task_config_mesos_fetcher_uris AS u ON u.task_config_id = c.id - LEFT OUTER JOIN task_config_docker_images AS di ON di.task_config_id = c.id - LEFT OUTER JOIN task_config_appc_images AS ai ON ai.task_config_id = c.id - LEFT OUTER JOIN task_config_volumes AS v ON v.task_config_id = c.id - LEFT OUTER JOIN task_constraints AS tc ON tc.task_config_id = c.id - LEFT OUTER JOIN limit_constraints as tlc ON tlc.constraint_id = tc.id - LEFT OUTER JOIN value_constraints as tvc ON tvc.constraint_id = tc.id - LEFT OUTER JOIN value_constraint_values AS tvcv ON tvcv.value_constraint_id = tvc.id - </sql> - - <select id="selectConfig" resultMap="taskConfigMap"> - <include refid="unscopedConfigSelect"/> - WHERE c.id = #{id} - </select> - - <select id="selectConfigsByJob" resultMap="taskConfigMap"> - <include refid="unscopedConfigSelect"/> - WHERE j.role = #{role} - AND j.environment = #{environment} - AND j.name = #{name} - </select> - - <insert id="insertConstraint" useGeneratedKeys="true" keyColumn="id" keyProperty="result.id"> - INSERT INTO task_constraints ( - task_config_id, - name - ) VALUES ( - #{configId}, - #{constraint.name} - ) - </insert> - - <insert id="insertLimitConstraint"> - INSERT INTO limit_constraints ( - constraint_id, - value - ) VALUES ( - #{constraintId}, - #{constraint.limit} - ) - </insert> - - <insert id="insertValueConstraint" useGeneratedKeys="true" keyColumn="id" keyProperty="result.id"> - INSERT INTO value_constraints ( - constraint_id, - negated - ) VALUES ( - #{constraintId}, - #{constraint.negated} - ) - </insert> - - <insert id="insertValueConstraintValues"> - INSERT INTO value_constraint_values ( - value_constraint_id, - value - ) VALUES ( - <foreach item="value" collection="values" separator="),("> - #{valueConstraintId}, - #{value} - </foreach> - ) - </insert> - - <insert id="insertRequestedPorts"> - INSERT INTO task_config_requested_ports ( - task_config_id, - port_name - ) VALUES ( - <foreach item="port" collection="ports" separator="),("> - #{configId}, - #{port} - </foreach> - ) - </insert> - - <insert id="insertResources"> - INSERT INTO task_resource ( - task_config_id, - type_id, - value - ) VALUES ( - <foreach item="value" collection="values" separator="),("> - #{configId}, - #{value.first}, - #{value.second} - </foreach> - ) - </insert> - - <insert id="insertTaskLinks" > - INSERT INTO task_config_task_links ( - task_config_id, - label, - url - ) VALUES ( - <foreach index="label" item="url" collection="links" separator="),("> - #{configId}, - #{label}, - #{url} - </foreach> - ) - </insert> - - <resultMap id="taskLinkMap" type="org.apache.aurora.common.collections.Pair"> - <constructor> - <arg column="label"/> - <arg column="url"/> - </constructor> - </resultMap> - - <select id="selectTaskLinks" resultMap="taskLinkMap"> - SELECT - id, - label, - url - FROM task_config_task_links - WHERE task_config_id = #{id} - </select> - - <select id="selectResources" resultMap="resourceMap"> - SELECT - id, - type_id, - value - FROM task_resource - WHERE task_config_id = #{id} - </select> - - <insert id="insertContainer" useGeneratedKeys="true" keyColumn="id" keyProperty="result.id"> - INSERT INTO task_config_docker_containers ( - task_config_id, - image - ) VALUES ( - #{configId}, - #{container.image} - ) - </insert> - - <insert id="insertDockerParameters"> - INSERT INTO task_config_docker_container_parameters ( - container_id, - name, - value - ) VALUES ( - <foreach item="parameter" collection="parameters" separator="),("> - #{containerId}, - #{parameter.name}, - #{parameter.value} - </foreach> - ) - </insert> - - <insert id="insertDockerImage"> - INSERT INTO task_config_docker_images ( - task_config_id, - name, - tag - ) VALUES ( - #{configId}, - #{name}, - #{tag} - ) - </insert> - - <insert id="insertAppcImage"> - INSERT INTO task_config_appc_images ( - task_config_id, - name, - image_id - ) VALUES ( - #{configId}, - #{name}, - #{imageId} - ) - </insert> - - <insert id="insertMetadata"> - INSERT INTO task_config_metadata ( - task_config_id, - key, - value - ) VALUES ( - <foreach item="entry" collection="metadata" separator="),("> - #{configId}, - #{entry.key}, - #{entry.value} - </foreach> - ) - </insert> - - <insert id="insertMesosFetcherUris"> - INSERT INTO task_config_mesos_fetcher_uris ( - task_config_id, - value, - extract, - cache - ) VALUES ( - <foreach item="entry" collection="uris" separator="),("> - #{configId}, - #{entry.value}, - #{entry.extract}, - #{entry.cache} - </foreach> - ) - </insert> - - <insert id="insertVolumes"> - INSERT INTO task_config_volumes ( - task_config_id, - host_path, - container_path, - mode - ) VALUES ( - <foreach item="volume" collection="volumes" separator="),("> - #{configId}, - #{volume.hostPath}, - #{volume.containerPath}, - #{volume.mode, typeHandler=org.apache.aurora.scheduler.storage.db.typehandlers.VolumeModeTypeHandler} - </foreach> - ) - </insert> - - <select id="selectAllRowIds" resultType="long"> - SELECT id FROM task_configs - </select> - - <delete id="deleteRow"> - DELETE FROM task_configs WHERE id = #{rowId} - </delete> -</mapper> http://git-wip-us.apache.org/repos/asf/aurora/blob/94276046/src/main/resources/org/apache/aurora/scheduler/storage/db/TaskMapper.xml ---------------------------------------------------------------------- diff --git a/src/main/resources/org/apache/aurora/scheduler/storage/db/TaskMapper.xml b/src/main/resources/org/apache/aurora/scheduler/storage/db/TaskMapper.xml deleted file mode 100644 index 0ecffab..0000000 --- a/src/main/resources/org/apache/aurora/scheduler/storage/db/TaskMapper.xml +++ /dev/null @@ -1,241 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" ?> -<!-- - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - --> - -<!DOCTYPE mapper - PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> -<mapper namespace="org.apache.aurora.scheduler.storage.db.TaskMapper"> - <cache type="org.apache.aurora.scheduler.storage.db.MyBatisCacheImpl"> - <property name="size" value="10000"/> - </cache> - <insert id="insertScheduledTask" useGeneratedKeys="true" keyColumn="id" keyProperty="result.id"> - INSERT INTO tasks ( - task_id, - slave_row_id, - instance_id, - status, - failure_count, - ancestor_task_id, - task_config_row_id, - ) VALUES ( - #{task.assignedTask.taskId}, - ( - SELECT ID - FROM host_attributes - WHERE slave_id = #{task.assignedTask.slaveId} - AND host = #{task.assignedTask.slaveHost} - ), - #{task.assignedTask.instanceId}, - #{task.status, typeHandler=org.apache.aurora.scheduler.storage.db.typehandlers.ScheduleStatusTypeHandler}, - #{task.failureCount}, - #{task.ancestorId}, - #{configId} - ) - </insert> - - <resultMap id="taskEventMap" type="org.apache.aurora.gen.TaskEvent"> - <id column="id"/> - <result property="status" - column="status" - typeHandler="org.apache.aurora.scheduler.storage.db.typehandlers.ScheduleStatusTypeHandler" /> - <result column="timestamp_ms" property="timestamp" /> - <result column="message" property="message" /> - <result column="scheduler_host" property="scheduler" /> - </resultMap> - - <resultMap id="scheduledTaskMap" type="org.apache.aurora.scheduler.storage.db.views.DbScheduledTask"> - <id column="row_id"/> - <result property="status" - column="status" - typeHandler="org.apache.aurora.scheduler.storage.db.typehandlers.ScheduleStatusTypeHandler" /> - <result column="task_id" property="assignedTask.taskId"/> - <result column="slave_id" property="assignedTask.slaveId"/> - <result column="slave_host" property="assignedTask.slaveHost"/> - <result column="instance_id" property="assignedTask.instanceId"/> - <association - property="assignedTask.task" - select="org.apache.aurora.scheduler.storage.db.TaskConfigMapper.selectConfig" - column="task_config_row_id" - foreignColumn="row_id"/> - <collection - property="assignedTask.assignedPorts" - resultMap="portMap" - columnPrefix="tp_"/> - <collection - property="taskEvents" - resultMap="taskEventMap" - columnPrefix="te_" - notNullColumn="status"/> - </resultMap> - - <sql id="unscopedSelect"> - <!-- - N.B. For any one-to-many relationship, results from the joined table *must* include the id - otherwise mybatis will not be able to disambiguate identical rows leading to an explosion - of related rows on each save. - --> - SELECT - t.id AS row_id, - t.task_config_row_id AS task_config_row_id, - t.task_id AS task_id, - t.instance_id AS instance_id, - t.status AS status, - t.failure_count AS failure_count, - t.ancestor_task_id AS ancestor_id, - j.role AS c_j_role, - j.environment AS c_j_environment, - j.name AS c_j_name, - h.slave_id AS slave_id, - h.host AS slave_host, - tp.id as tp_id, - tp.name as tp_name, - tp.port as tp_port, - te.id as te_id, - te.timestamp_ms as te_timestamp, - te.status as te_status, - te.message as te_message, - te.scheduler_host as te_scheduler - FROM tasks AS t - INNER JOIN task_configs as c ON c.id = t.task_config_row_id - INNER JOIN job_keys AS j ON j.id = c.job_key_id - LEFT OUTER JOIN task_ports as tp ON tp.task_row_id = t.id - LEFT OUTER JOIN task_events as te ON te.task_row_id = t.id - LEFT OUTER JOIN host_attributes AS h ON h.id = t.slave_row_id - </sql> - - <select id="selectById" resultMap="scheduledTaskMap"> - <include refid="unscopedSelect"/> - WHERE - t.task_id = #{taskId} - </select> - - <select id="select" resultMap="scheduledTaskMap"> - <include refid="unscopedSelect"/> - <where> - <if test="role != null"> - j.role = #{role} - </if> - <if test="environment != null"> - AND j.environment = #{environment} - </if> - <if test="jobName != null"> - AND j.name = #{jobName} - </if> - <if test="!taskIds.isEmpty()"> - AND t.task_id IN ( - <foreach item="task_id" collection="taskIds" separator=","> - #{task_id} - </foreach> - ) - </if> - <if test="!statuses.isEmpty()"> - AND t.status IN ( - <foreach item="element" collection="statuses" separator=","> - #{element, typeHandler=org.apache.aurora.scheduler.storage.db.typehandlers.ScheduleStatusTypeHandler} - </foreach> - ) - </if> - <if test="!instanceIds.isEmpty()"> - AND t.instance_id IN ( - <foreach item="instance_id" collection="instanceIds" separator=","> - #{instance_id} - </foreach> - ) - </if> - <if test="!slaveHosts.isEmpty()"> - AND h.host IN ( - <foreach item="host" collection="slaveHosts" separator=","> - #{host} - </foreach> - ) - </if> - <if test="!jobKeys.isEmpty()"> - AND ( - <foreach item="jobKey" collection="jobKeys" open="(" separator=") OR (" close=")"> - j.role = #{jobKey.role} - AND j.name = #{jobKey.name} - AND j.environment = #{jobKey.environment} - </foreach> - ) - </if> - </where> - </select> - - <select id="selectJobKeys" resultMap="org.apache.aurora.scheduler.storage.db.JobKeyMapper.jobKeyMap"> - SELECT DISTINCT - j.role AS role, - j.environment AS environment, - j.name AS name - FROM tasks AS t - INNER JOIN task_configs as c ON c.id = t.task_config_row_id - INNER JOIN job_keys AS j ON j.id = c.job_key_id - </select> - - <insert id="insertTaskEvents"> - INSERT INTO task_events( - task_row_id, - timestamp_ms, - status, - message, - scheduler_host - ) VALUES ( - <foreach item="event" collection="events" separator="),("> - #{taskRowId}, - #{event.timestamp}, - #{event.status, typeHandler=org.apache.aurora.scheduler.storage.db.typehandlers.ScheduleStatusTypeHandler}, - #{event.message}, - #{event.scheduler} - </foreach> - ) - </insert> - - <insert id="insertPorts"> - INSERT INTO task_ports( - task_row_id, - name, - port - ) VALUES ( - <foreach index="name" item="port" collection="ports" separator="),("> - #{taskRowId}, - #{name}, - #{port} - </foreach> - ) - </insert> - - <resultMap id="portMap" type="org.apache.aurora.scheduler.storage.db.views.DbAssginedPort"> - <id column="id"/> - <result column="name" property="name" /> - <result column="port" property="port" /> - </resultMap> - - <delete id="truncate"> - <!-- - This assumes cascading deletes will clean up all references. Also, once the job store is - migrated, there will be a clash between deletes on the two that needs to be resolved. At that - point it probably makes sense to remove all of the store-specific truncate verbs and use a - single control. - --> - DELETE FROM tasks - </delete> - - <delete id="deleteTasks"> - DELETE FROM tasks WHERE task_id IN ( - <foreach item="task_id" collection="taskIds" separator=","> - #{task_id} - </foreach> - ) - </delete> -</mapper> http://git-wip-us.apache.org/repos/asf/aurora/blob/94276046/src/main/resources/org/apache/aurora/scheduler/storage/db/schema.sql ---------------------------------------------------------------------- diff --git a/src/main/resources/org/apache/aurora/scheduler/storage/db/schema.sql b/src/main/resources/org/apache/aurora/scheduler/storage/db/schema.sql deleted file mode 100644 index 7a86f47..0000000 --- a/src/main/resources/org/apache/aurora/scheduler/storage/db/schema.sql +++ /dev/null @@ -1,392 +0,0 @@ -/** - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - --- schema for h2 engine. -/* TODO(maxim): Consider using TIMESTAMP instead of BIGINT for all "timestamp" fields below. */ - -CREATE TABLE framework_id( - id INT PRIMARY KEY, - framework_id VARCHAR NOT NULL, - - UNIQUE(framework_id) -); - -CREATE TABLE job_keys( - id IDENTITY, - role VARCHAR NOT NULL, - environment VARCHAR NOT NULL, - name VARCHAR NOT NULL, - - UNIQUE(role, environment, name) -); - -CREATE TABLE locks( - id IDENTITY, - job_key_id BIGINT NOT NULL REFERENCES job_keys(id), - token VARCHAR NOT NULL, - user VARCHAR NOT NULL, - timestampMs BIGINT NOT NULL, - message VARCHAR, - - UNIQUE(job_key_id), - UNIQUE(token) -); - -CREATE TABLE maintenance_modes( - id INT PRIMARY KEY, - name VARCHAR NOT NULL, - - UNIQUE(name) -); - -CREATE TABLE host_attributes( - id IDENTITY, - host VARCHAR NOT NULL, - mode INT NOT NULL REFERENCES maintenance_modes(id), - slave_id VARCHAR NOT NULL, - - UNIQUE(host), - UNIQUE(slave_id), -); - -CREATE TABLE host_attribute_values( - id IDENTITY, - host_attribute_id BIGINT NOT NULL REFERENCES host_attributes(id) ON DELETE CASCADE, - name VARCHAR NOT NULL, - value VARCHAR NOT NULL, - - UNIQUE(host_attribute_id, name, value) -); - -/** - * NOTE: This table is truncated by TaskMapper, which will cause a conflict when the table is shared - * with the forthcoming jobs table. See note in TaskMapper about this before migrating MemJobStore. - */ -CREATE TABLE task_configs( - id IDENTITY, - job_key_id BIGINT NOT NULL REFERENCES job_keys(id), - creator_user VARCHAR NOT NULL, - service BOOLEAN NOT NULL, - num_cpus DOUBLE NOT NULL, - ram_mb BIGINT NOT NULL, - disk_mb BIGINT NOT NULL, - priority INTEGER NOT NULL, - max_task_failures INTEGER NOT NULL, - production BOOLEAN NOT NULL, - contact_email VARCHAR, - executor_name VARCHAR, - executor_data VARCHAR, - tier VARCHAR -); - -CREATE TABLE resource_types( - id INT PRIMARY KEY, - name VARCHAR NOT NULL, - - UNIQUE(name) -); - -CREATE TABLE task_resource( - id IDENTITY, - task_config_id BIGINT NOT NULL REFERENCES task_configs(id) ON DELETE CASCADE, - type_id INT NOT NULL REFERENCES resource_types(id), - value VARCHAR NOT NULL, - - UNIQUE(task_config_id, type_id, value) -); - -CREATE TABLE quotas( - id IDENTITY, - role VARCHAR NOT NULL, - num_cpus DOUBLE NOT NULL, - ram_mb BIGINT NOT NULL, - disk_mb BIGINT NOT NULL, - - UNIQUE(role) -); - -CREATE TABLE quota_resource( - id IDENTITY, - quota_id BIGINT NOT NULL REFERENCES quotas(id) ON DELETE CASCADE, - type_id INT NOT NULL REFERENCES resource_types(id), - value VARCHAR NOT NULL, - - UNIQUE(quota_id, type_id) -); - -CREATE TABLE task_constraints( - id IDENTITY, - task_config_id BIGINT NOT NULL REFERENCES task_configs(id) ON DELETE CASCADE, - name VARCHAR NOT NULL, - - UNIQUE(task_config_id, name) -); - -CREATE TABLE value_constraints( - id IDENTITY, - constraint_id BIGINT NOT NULL REFERENCES task_constraints(id) ON DELETE CASCADE, - negated BOOLEAN NOT NULL, - - UNIQUE(constraint_id) -); - -CREATE TABLE value_constraint_values( - id IDENTITY, - value_constraint_id BIGINT NOT NULL REFERENCES value_constraints(id) ON DELETE CASCADE, - value VARCHAR NOT NULL, - - UNIQUE(value_constraint_id, value) -); - -CREATE TABLE limit_constraints( - id IDENTITY, - constraint_id BIGINT NOT NULL REFERENCES task_constraints(id) ON DELETE CASCADE, - value INTEGER NOT NULL, - - UNIQUE(constraint_id) -); - -CREATE TABLE task_config_requested_ports( - id IDENTITY, - task_config_id BIGINT NOT NULL REFERENCES task_configs(id) ON DELETE CASCADE, - port_name VARCHAR NOT NULL, - - UNIQUE(task_config_id, port_name) -); - -CREATE TABLE task_config_task_links( - id IDENTITY, - task_config_id BIGINT NOT NULL REFERENCES task_configs(id) ON DELETE CASCADE, - label VARCHAR NOT NULL, - url VARCHAR NOT NULL, - - UNIQUE(task_config_id, label) -); - -CREATE TABLE task_config_metadata( - id IDENTITY, - task_config_id BIGINT NOT NULL REFERENCES task_configs(id) ON DELETE CASCADE, - key VARCHAR NOT NULL, - value VARCHAR NOT NULL -); - -CREATE TABLE task_config_mesos_fetcher_uris( - id IDENTITY, - task_config_id BIGINT NOT NULL REFERENCES task_configs(id) ON DELETE CASCADE, - value VARCHAR NOT NULL, - extract BOOLEAN NOT NULL, - cache BOOLEAN NOT NULL -); - -CREATE TABLE task_config_docker_containers( - id IDENTITY, - task_config_id BIGINT NOT NULL REFERENCES task_configs(id) ON DELETE CASCADE, - image VARCHAR NOT NULL, - - UNIQUE(task_config_id) -); - -CREATE TABLE task_config_docker_container_parameters( - id IDENTITY, - container_id BIGINT NOT NULL REFERENCES task_config_docker_containers(id) ON DELETE CASCADE, - name VARCHAR NOT NULL, - value VARCHAR NOT NULL -); - -CREATE TABLE task_config_docker_images( - id IDENTITY, - task_config_id BIGINT NOT NULL REFERENCES task_configs(id) ON DELETE CASCADE, - name VARCHAR NOT NULL, - tag VARCHAR NOT NULL, - - UNIQUE(task_config_id) -); - -CREATE TABLE task_config_appc_images( - id IDENTITY, - task_config_id BIGINT NOT NULL REFERENCES task_configs(id) ON DELETE CASCADE, - name VARCHAR NOT NULL, - image_id VARCHAR NOT NULL, - - UNIQUE(task_config_id) -); - -CREATE TABLE volume_modes( - id INT PRIMARY KEY, - name VARCHAR NOT NULL, - - UNIQUE(name) -); - -CREATE TABLE task_config_volumes( - id IDENTITY, - task_config_id BIGINT NOT NULL REFERENCES task_configs(id) ON DELETE CASCADE, - host_path VARCHAR NOT NULL, - container_path VARCHAR NOT NULL, - mode INT NOT NULL REFERENCES volume_modes(id), -); - -CREATE TABLE task_states( - id INT PRIMARY KEY, - name VARCHAR NOT NULL, - - UNIQUE(name) -); - -CREATE TABLE tasks( - id IDENTITY, - task_id VARCHAR NOT NULL, - slave_row_id BIGINT REFERENCES host_attributes(id), - instance_id INTEGER NOT NULL, - status INT NOT NULL REFERENCES task_states(id), - failure_count INTEGER NOT NULL, - ancestor_task_id VARCHAR NULL, - task_config_row_id BIGINT NOT NULL REFERENCES task_configs(id), - - UNIQUE(task_id) -); - -CREATE TABLE task_events( - id IDENTITY, - task_row_id BIGINT NOT NULL REFERENCES tasks(id) ON DELETE CASCADE, - timestamp_ms BIGINT NOT NULL, - status INT NOT NULL REFERENCES task_states(id), - message VARCHAR NULL, - scheduler_host VARCHAR NULL, -); - -CREATE TABLE task_ports( - id IDENTITY, - task_row_id BIGINT NOT NULL REFERENCES tasks(id) ON DELETE CASCADE, - name VARCHAR NOT NULL, - port INT NOT NULL, - - UNIQUE(task_row_id, name) -); - -CREATE TABLE cron_policies( - id INT PRIMARY KEY, - name VARCHAR NOT NULL, - - UNIQUE(name) -); - -CREATE TABLE cron_jobs( - id IDENTITY, - job_key_id BIGINT NOT NULL REFERENCES job_keys(id), - creator_user VARCHAR NOT NULL, - cron_schedule VARCHAR NOT NULL, - cron_collision_policy INT NOT NULL REFERENCES cron_policies(id), - task_config_row_id BIGINT NOT NULL REFERENCES task_configs(id), - instance_count INT NOT NULL, - - UNIQUE(job_key_id) -); - -CREATE TABLE job_instance_update_actions( - id INT PRIMARY KEY, - name VARCHAR NOT NULL, - - UNIQUE(name) -); - -CREATE TABLE job_update_statuses( - id INT PRIMARY KEY, - name VARCHAR NOT NULL, - - UNIQUE(name) -); - -CREATE TABLE job_updates( - id IDENTITY, - job_key_id BIGINT NOT NULL REFERENCES job_keys(id), - update_id VARCHAR NOT NULL, - user VARCHAR NOT NULL, - update_group_size INT NOT NULL, - max_per_instance_failures INT NOT NULL, - max_failed_instances INT NOT NULL, - min_wait_in_instance_running_ms INT NOT NULL, - rollback_on_failure BOOLEAN NOT NULL, - wait_for_batch_completion BOOLEAN NOT NULL, - block_if_no_pulses_after_ms INT NULL, - - UNIQUE(update_id, job_key_id) -); - -CREATE TABLE job_update_metadata( - id IDENTITY, - update_row_id BIGINT NOT NULL REFERENCES job_updates(id) ON DELETE CASCADE, - key VARCHAR NOT NULL, - value VARCHAR NOT NULL -); - -CREATE TABLE job_update_locks( - id IDENTITY, - update_row_id BIGINT NOT NULL REFERENCES job_updates(id) ON DELETE CASCADE, - lock_token VARCHAR NOT NULL REFERENCES locks(token) ON DELETE CASCADE, - - UNIQUE(update_row_id), - UNIQUE(lock_token) -); - -CREATE TABLE job_update_configs( - id IDENTITY, - update_row_id BIGINT NOT NULL REFERENCES job_updates(id) ON DELETE CASCADE, - task_config_row_id BIGINT NOT NULL REFERENCES task_configs(id), - is_new BOOLEAN NOT NULL -); - -CREATE TABLE job_updates_to_instance_overrides( - id IDENTITY, - update_row_id BIGINT NOT NULL REFERENCES job_updates(id) ON DELETE CASCADE, - first INT NOT NULL, - last INT NOT NULL, - - UNIQUE(update_row_id, first, last) -); - -CREATE TABLE job_updates_to_desired_instances( - id IDENTITY, - update_row_id BIGINT NOT NULL REFERENCES job_updates(id) ON DELETE CASCADE, - first INT NOT NULL, - last INT NOT NULL, - - UNIQUE(update_row_id, first, last) -); - -CREATE TABLE job_update_configs_to_instances( - id IDENTITY, - config_id BIGINT NOT NULL REFERENCES job_update_configs(id) ON DELETE CASCADE, - first INT NOT NULL, - last INT NOT NULL, - - UNIQUE(config_id, first, last) -); - -CREATE TABLE job_update_events( - id IDENTITY, - update_row_id BIGINT NOT NULL REFERENCES job_updates(id) ON DELETE CASCADE, - status INT NOT NULL REFERENCES job_update_statuses(id), - timestamp_ms BIGINT NOT NULL, - user VARCHAR, - message VARCHAR -); - -CREATE TABLE job_instance_update_events( - id IDENTITY, - update_row_id BIGINT NOT NULL REFERENCES job_updates(id) ON DELETE CASCADE, - action INT NOT NULL REFERENCES job_instance_update_actions(id), - instance_id INT NOT NULL, - timestamp_ms BIGINT NOT NULL -); http://git-wip-us.apache.org/repos/asf/aurora/blob/94276046/src/test/java/org/apache/aurora/scheduler/async/AsyncModuleTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/aurora/scheduler/async/AsyncModuleTest.java b/src/test/java/org/apache/aurora/scheduler/async/AsyncModuleTest.java index 74956cd..729fbf1 100644 --- a/src/test/java/org/apache/aurora/scheduler/async/AsyncModuleTest.java +++ b/src/test/java/org/apache/aurora/scheduler/async/AsyncModuleTest.java @@ -87,8 +87,7 @@ public class AsyncModuleTest extends EasyMockTest { assertEquals( ImmutableMap.of( RegisterGauges.TIMEOUT_QUEUE_GAUGE, 0, - RegisterGauges.ASYNC_TASKS_GAUGE, 0L, - RegisterGauges.DELAY_QUEUE_GAUGE, 0), + RegisterGauges.ASYNC_TASKS_GAUGE, 0L), statsProvider.getAllValues() ); }
