Search in sources :

Example 1 with KettleObjectExistsException

use of org.pentaho.di.core.exception.KettleObjectExistsException in project pentaho-kettle by pentaho.

the class KettleDatabaseRepositoryPartitionSchemaDelegate method savePartitionSchema.

public void savePartitionSchema(PartitionSchema partitionSchema, ObjectId id_transformation, boolean isUsedByTransformation, boolean overwrite) throws KettleException {
    // 
    if (partitionSchema.getObjectId() == null) {
        partitionSchema.setObjectId(getPartitionSchemaID(partitionSchema.getName()));
    }
    if (partitionSchema.getObjectId() == null) {
        // New Slave Server
        partitionSchema.setObjectId(insertPartitionSchema(partitionSchema));
    } else {
        ObjectId existingPartitionSchemaId = partitionSchema.getObjectId();
        // If we received a partitionSchemaId and it is different from the partition schema we are working with...
        if (existingPartitionSchemaId != null && !partitionSchema.getObjectId().equals(existingPartitionSchemaId)) {
            // A partition with this name already exists
            if (overwrite) {
                // Proceed with save, removing the original version from the repository first
                repository.deletePartitionSchema(existingPartitionSchemaId);
                updatePartitionSchema(partitionSchema);
                repository.delPartitions(partitionSchema.getObjectId());
            } else {
                throw new KettleObjectExistsException("Failed to save object to repository. Object [" + partitionSchema.getName() + "] already exists.");
            }
        } else {
            // There are no naming collisions (either it is the same object or the name is unique)
            updatePartitionSchema(partitionSchema);
            repository.delPartitions(partitionSchema.getObjectId());
        }
    }
    // 
    for (int i = 0; i < partitionSchema.getPartitionIDs().size(); i++) {
        insertPartition(partitionSchema.getObjectId(), partitionSchema.getPartitionIDs().get(i));
    }
    // 
    if (isUsedByTransformation) {
        repository.insertTransformationPartitionSchema(id_transformation, partitionSchema.getObjectId());
    }
}
Also used : ObjectId(org.pentaho.di.repository.ObjectId) KettleObjectExistsException(org.pentaho.di.core.exception.KettleObjectExistsException)

Example 2 with KettleObjectExistsException

use of org.pentaho.di.core.exception.KettleObjectExistsException in project pentaho-kettle by pentaho.

the class KettleDatabaseRepositoryPartitionSchemaDelegate method insertPartitionSchema.

public synchronized ObjectId insertPartitionSchema(PartitionSchema partitionSchema) throws KettleException {
    if (getPartitionSchemaID(partitionSchema.getName()) != null) {
        // This partition schema name is already in use. Throw an exception.
        throw new KettleObjectExistsException("Failed to create object in repository. Object [" + partitionSchema.getName() + "] already exists.");
    }
    ObjectId id = repository.connectionDelegate.getNextPartitionSchemaID();
    RowMetaAndData table = new RowMetaAndData();
    table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_PARTITION_SCHEMA_ID_PARTITION_SCHEMA), id);
    table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_PARTITION_SCHEMA_NAME), partitionSchema.getName());
    table.addValue(new ValueMetaBoolean(KettleDatabaseRepository.FIELD_PARTITION_SCHEMA_DYNAMIC_DEFINITION), partitionSchema.isDynamicallyDefined());
    table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_PARTITION_SCHEMA_PARTITIONS_PER_SLAVE), partitionSchema.getNumberOfPartitionsPerSlave());
    repository.connectionDelegate.getDatabase().prepareInsert(table.getRowMeta(), KettleDatabaseRepository.TABLE_R_PARTITION_SCHEMA);
    repository.connectionDelegate.getDatabase().setValuesInsert(table);
    repository.connectionDelegate.getDatabase().insertRow();
    repository.connectionDelegate.getDatabase().closeInsert();
    return id;
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) ObjectId(org.pentaho.di.repository.ObjectId) KettleObjectExistsException(org.pentaho.di.core.exception.KettleObjectExistsException) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) ValueMetaBoolean(org.pentaho.di.core.row.value.ValueMetaBoolean)

Example 3 with KettleObjectExistsException

use of org.pentaho.di.core.exception.KettleObjectExistsException in project pentaho-kettle by pentaho.

the class KettleDatabaseRepositorySlaveServerDelegate method insertSlave.

public synchronized ObjectId insertSlave(SlaveServer slaveServer) throws KettleException {
    if (getSlaveID(slaveServer.getName()) != null) {
        // This slave server name is already in use. Throw an exception.
        throw new KettleObjectExistsException("Failed to create object in repository. Object [" + slaveServer.getName() + "] already exists.");
    }
    ObjectId id = repository.connectionDelegate.getNextSlaveServerID();
    RowMetaAndData table = new RowMetaAndData();
    table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_SLAVE_ID_SLAVE), id);
    table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_SLAVE_NAME), slaveServer.getName());
    table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_SLAVE_HOST_NAME), slaveServer.getHostname());
    table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_SLAVE_PORT), slaveServer.getPort());
    table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_SLAVE_WEB_APP_NAME), slaveServer.getWebAppName());
    table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_SLAVE_USERNAME), slaveServer.getUsername());
    table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_SLAVE_PASSWORD), Encr.encryptPasswordIfNotUsingVariables(slaveServer.getPassword()));
    table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_SLAVE_PROXY_HOST_NAME), slaveServer.getProxyHostname());
    table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_SLAVE_PROXY_PORT), slaveServer.getProxyPort());
    table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_SLAVE_NON_PROXY_HOSTS), slaveServer.getNonProxyHosts());
    table.addValue(new ValueMetaBoolean(KettleDatabaseRepository.FIELD_SLAVE_MASTER), Boolean.valueOf(slaveServer.isMaster()));
    repository.connectionDelegate.getDatabase().prepareInsert(table.getRowMeta(), KettleDatabaseRepository.TABLE_R_SLAVE);
    repository.connectionDelegate.getDatabase().setValuesInsert(table);
    repository.connectionDelegate.getDatabase().insertRow();
    repository.connectionDelegate.getDatabase().closeInsert();
    return id;
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) ObjectId(org.pentaho.di.repository.ObjectId) KettleObjectExistsException(org.pentaho.di.core.exception.KettleObjectExistsException) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) ValueMetaBoolean(org.pentaho.di.core.row.value.ValueMetaBoolean)

Example 4 with KettleObjectExistsException

use of org.pentaho.di.core.exception.KettleObjectExistsException in project pentaho-kettle by pentaho.

the class KettleDatabaseRepositoryClusterSchemaDelegate method saveClusterSchema.

public void saveClusterSchema(ClusterSchema clusterSchema, String versionComment, ObjectId id_transformation, boolean isUsedByTransformation, boolean overwrite) throws KettleException {
    ObjectId existingClusterSchemaId = getClusterID(clusterSchema.getName());
    if (existingClusterSchemaId != null) {
        clusterSchema.setObjectId(existingClusterSchemaId);
    }
    if (clusterSchema.getObjectId() == null) {
        // New Slave Server
        clusterSchema.setObjectId(insertCluster(clusterSchema));
    } else {
        // If we received a clusterSchemaId and it is different from the cluster schema we are working with...
        if (existingClusterSchemaId != null && !clusterSchema.getObjectId().equals(existingClusterSchemaId)) {
            // A cluster with this name already exists
            if (overwrite) {
                // Proceed with save, removing the original version from the repository first
                repository.deleteClusterSchema(existingClusterSchemaId);
                updateCluster(clusterSchema);
            } else {
                throw new KettleObjectExistsException("Failed to save object to repository. Object [" + clusterSchema.getName() + "] already exists.");
            }
        } else {
            // There are no naming collisions (either it is the same object or the name is unique)
            updateCluster(clusterSchema);
        }
    }
    repository.delClusterSlaves(clusterSchema.getObjectId());
    // Also save the used slave server references.
    for (int i = 0; i < clusterSchema.getSlaveServers().size(); i++) {
        SlaveServer slaveServer = clusterSchema.getSlaveServers().get(i);
        if (slaveServer.getObjectId() == null) {
            // oops, not yet saved!
            repository.save(slaveServer, versionComment, null, id_transformation, isUsedByTransformation, overwrite);
        }
        repository.insertClusterSlave(clusterSchema, slaveServer);
    }
    // Only save it if it's really used by the transformation
    if (isUsedByTransformation) {
        repository.insertTransformationCluster(id_transformation, clusterSchema.getObjectId());
    }
}
Also used : ObjectId(org.pentaho.di.repository.ObjectId) KettleObjectExistsException(org.pentaho.di.core.exception.KettleObjectExistsException) SlaveServer(org.pentaho.di.cluster.SlaveServer)

Example 5 with KettleObjectExistsException

use of org.pentaho.di.core.exception.KettleObjectExistsException in project pentaho-kettle by pentaho.

the class RepositoryBrowserController method rename.

public ObjectId rename(String id, String path, String newName, String type, String oldName) throws KettleException {
    RepositoryDirectoryInterface repositoryDirectoryInterface = findDirectory(path);
    ObjectId objectId = null;
    switch(type) {
        case JOB:
            if (getRepository().exists(newName, repositoryDirectoryInterface, RepositoryObjectType.JOB)) {
                throw new KettleObjectExistsException();
            }
            if (isJobOpened(id, path, oldName)) {
                throw new KettleJobException();
            }
            renameRecent(id, type, newName);
            objectId = getRepository().renameJob(() -> id, repositoryDirectoryInterface, newName);
            break;
        case TRANSFORMATION:
            if (getRepository().exists(newName, repositoryDirectoryInterface, RepositoryObjectType.TRANSFORMATION)) {
                throw new KettleObjectExistsException();
            }
            if (isTransOpened(id, path, oldName)) {
                throw new KettleTransException();
            }
            renameRecent(id, type, newName);
            objectId = getRepository().renameTransformation(() -> id, repositoryDirectoryInterface, newName);
            break;
        case FOLDER:
            isFileOpenedInFolder(path);
            RepositoryDirectoryInterface parent = findDirectory(path).getParent();
            if (parent == null) {
                parent = findDirectory(path);
            }
            RepositoryDirectoryInterface child = parent.findChild(newName);
            if (child != null) {
                throw new KettleObjectExistsException();
            }
            if (getRepository() instanceof RepositoryExtended) {
                objectId = ((RepositoryExtended) getRepository()).renameRepositoryDirectory(() -> id, null, newName, true);
            } else {
                objectId = getRepository().renameRepositoryDirectory(() -> id, null, newName);
            }
            break;
    }
    return objectId;
}
Also used : RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) ObjectId(org.pentaho.di.repository.ObjectId) KettleObjectExistsException(org.pentaho.di.core.exception.KettleObjectExistsException) KettleTransException(org.pentaho.di.core.exception.KettleTransException) RepositoryExtended(org.pentaho.di.repository.RepositoryExtended) KettleJobException(org.pentaho.di.core.exception.KettleJobException)

Aggregations

KettleObjectExistsException (org.pentaho.di.core.exception.KettleObjectExistsException)8 ObjectId (org.pentaho.di.repository.ObjectId)7 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)3 ValueMetaBoolean (org.pentaho.di.core.row.value.ValueMetaBoolean)3 ValueMetaInteger (org.pentaho.di.core.row.value.ValueMetaInteger)3 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)3 SlaveServer (org.pentaho.di.cluster.SlaveServer)1 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)1 KettleException (org.pentaho.di.core.exception.KettleException)1 KettleJobException (org.pentaho.di.core.exception.KettleJobException)1 KettleTransException (org.pentaho.di.core.exception.KettleTransException)1 RepositoryDirectoryInterface (org.pentaho.di.repository.RepositoryDirectoryInterface)1 RepositoryExtended (org.pentaho.di.repository.RepositoryExtended)1 SharedObjects (org.pentaho.di.shared.SharedObjects)1