use of com.navercorp.pinpoint.hbase.schema.reader.InvalidHbaseSchemaException in project pinpoint by naver.
the class HbaseSchemaCommandManager method applyChangeSet.
public void applyChangeSet(ChangeSet changeSet) {
Objects.requireNonNull(changeSet, "changeSet");
List<TableChange> tableChanges = changeSet.getTableChanges();
try {
for (TableChange tableChange : tableChanges) {
applyTableChange(tableChange);
}
} catch (Exception e) {
throw new InvalidHbaseSchemaException("Error applying changeSet : " + changeSet.getId(), e);
}
}
use of com.navercorp.pinpoint.hbase.schema.reader.InvalidHbaseSchemaException in project pinpoint by naver.
the class HbaseSchemaCommandManagerTest method failedChangesShouldNotAffectTheSchema.
@Test
public void failedChangesShouldNotAffectTheSchema() {
String namespace = "namespace";
String tableName = "table";
String columnFamilyName = "CF";
HbaseSchemaCommandManager manager = new HbaseSchemaCommandManager(namespace, null);
// initial create table
ColumnFamilyChange columnFamilyChange = newColumnFamilyChange(columnFamilyName);
TableChange createTableChange = newTableChange(ChangeType.CREATE, tableName, columnFamilyChange);
ChangeSet createTableChangeSet = newChangeSet(createTableChange);
manager.applyChangeSet(createTableChangeSet);
List<HTableDescriptor> initialSnapshot = manager.getSchemaSnapshot();
// modify non-existing table
TableChange modifyNonExistingTableChange = newTableChange(ChangeType.MODIFY, "nonExistingTable", newColumnFamilyChange("newCF"));
ChangeSet modifyNonExistingTableChangeSet = newChangeSet(modifyNonExistingTableChange);
try {
manager.applyChangeSet(modifyNonExistingTableChangeSet);
fail("Expected an InvalidHbaseSchemaException to be thrown");
} catch (InvalidHbaseSchemaException expected) {
List<HTableDescriptor> currentSnapshot = manager.getSchemaSnapshot();
assertThat(currentSnapshot, equalTo(initialSnapshot));
}
// create existing table
TableChange createExistingTableChange = newTableChange(ChangeType.CREATE, tableName);
ChangeSet createExistingTableChangeSet = newChangeSet(createExistingTableChange);
try {
manager.applyChangeSet(createExistingTableChangeSet);
fail("Expected an InvalidHbaseSchemaException to be thrown");
} catch (InvalidHbaseSchemaException expected) {
List<HTableDescriptor> currentSnapshot = manager.getSchemaSnapshot();
assertThat(currentSnapshot, equalTo(initialSnapshot));
}
// create existing column family
ColumnFamilyChange createExistingColumnFamilyChange = newColumnFamilyChange(columnFamilyName);
TableChange createExistingColumnFamilyTableChange = newTableChange(ChangeType.MODIFY, tableName, createExistingColumnFamilyChange);
ChangeSet createExistingColumnFamilyChangeSet = newChangeSet(createExistingColumnFamilyTableChange);
try {
manager.applyChangeSet(createExistingColumnFamilyChangeSet);
fail("Expected an InvalidHbaseSchemaException to be thrown");
} catch (InvalidHbaseSchemaException expected) {
List<HTableDescriptor> currentSnapshot = manager.getSchemaSnapshot();
assertThat(currentSnapshot, equalTo(initialSnapshot));
}
}
use of com.navercorp.pinpoint.hbase.schema.reader.InvalidHbaseSchemaException in project pinpoint by naver.
the class ColumnFamilyChangeMapper method mapCreate.
public ColumnFamilyChange mapCreate(Table.CreateColumnFamily createColumnFamily) {
String name = createColumnFamily.getName();
if (StringUtils.isEmpty(name)) {
throw new InvalidHbaseSchemaException("ColumnFamily name must not be empty");
}
ColumnFamilyConfiguration columnFamilyConfiguration = columnFamilyConfigurationMapper.mapConfiguration(createColumnFamily.getConfiguration());
return new CreateColumnFamilyChange(name, columnFamilyConfiguration);
}
use of com.navercorp.pinpoint.hbase.schema.reader.InvalidHbaseSchemaException in project pinpoint by naver.
the class HbaseSchemaManagerRunner method run.
@Override
public void run(ApplicationArguments args) throws Exception {
logger.info("Launched with arguments : {}", Arrays.asList(args.getSourceArgs()));
ProgramCommand programCommand = ProgramCommand.parseArgs(args);
ProgramOptions programOptions = ProgramOptions.parseArgs(args);
HbaseSchemaManagerTask task = taskFactory.create(programCommand, programOptions);
try {
task.run(programCommand.getCommandArgs());
} catch (HbaseSchemaParseException | InvalidHbaseSchemaException e) {
logger.error(Markers.TERMINAL, "{}, cause : {}", e.getMessage(), e.getCause().getMessage());
logger.error(Markers.APP_LOG, "Hbase schema error.", e);
} catch (HbaseSystemException e) {
logger.error(Markers.TERMINAL, "Error accessing hbase : {}", e.getMessage());
logger.error(Markers.APP_LOG, "Hbase error.", e);
} catch (Exception e) {
logger.error(Markers.TERMINAL, "Error running '{}' : {}", programCommand.getCommand(), e.getMessage());
logger.error(Markers.APP_LOG, "Error running '" + programCommand.getCommand() + "'.", e);
}
}
use of com.navercorp.pinpoint.hbase.schema.reader.InvalidHbaseSchemaException in project pinpoint by naver.
the class HbaseSchemaMapper method mapChangeSets.
private Collection<ChangeSet> mapChangeSets(List<com.navercorp.pinpoint.hbase.schema.definition.xml.ChangeSet> schemaChangeSets) {
if (CollectionUtils.isEmpty(schemaChangeSets)) {
return Collections.emptySet();
}
Map<String, ChangeSet> changeSets = new LinkedHashMap<>();
for (com.navercorp.pinpoint.hbase.schema.definition.xml.ChangeSet schemaChangeSet : schemaChangeSets) {
String changeSetId = schemaChangeSet.getId();
if (changeSets.containsKey(changeSetId)) {
throw new InvalidHbaseSchemaException("Duplicate changeSet id : " + changeSetId);
}
ChangeSet changeSet = changeSetMapper.mapChangeSet(schemaChangeSet);
changeSets.put(changeSetId, changeSet);
}
return changeSets.values();
}
Aggregations